Skip to content

Commit

Permalink
Shake out implications of user.key() returning &str (#7)
Browse files Browse the repository at this point in the history
Changing user.key() to return &str created a few compile errors in the SDK - this fixes them.
  • Loading branch information
samstokes committed May 12, 2021
1 parent 1dd7ff5 commit 9bfec97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ fn process_event(
}

fn notice_user(user_cache: &mut LruCache<String, ()>, user: &MaybeInlinedUser) -> bool {
let key = user.key();
let key = user.key().to_string();

if user_cache.get(key).is_none() {
if user_cache.get(&key).is_none() {
trace!("noticing new user {:?}", key);
user_cache.put(key.clone(), ());
user_cache.put(key, ());
true
} else {
trace!("ignoring already-seen user {:?}", key);
Expand Down
9 changes: 3 additions & 6 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl MaybeInlinedUser {
}
}

pub fn key(&self) -> &String {
pub fn key(&self) -> &str {
self.user().key()
}
}
Expand Down Expand Up @@ -123,8 +123,6 @@ impl Event {
default: FlagValue,
send_reason: bool,
) -> Self {
let user_key = user.key().clone();

// unwrap is safe here because value should have been replaced with default if it was None.
// TODO that is ugly, use the type system to fix it
let value = detail.value.unwrap();
Expand All @@ -136,11 +134,11 @@ impl Event {
};

Event::FeatureRequest {
user_key: user.key().to_string(),
base: BaseEvent {
creation_date: Self::now(),
user,
},
user_key,
key: flag_key.to_owned(),
default,
reason,
Expand All @@ -152,13 +150,12 @@ impl Event {
}

pub fn new_identify(user: User) -> Self {
let key = user.key().clone();
Event::Identify(IdentifyEvent {
key: user.key().to_string(),
base: BaseEvent {
creation_date: Self::now(),
user: MaybeInlinedUser::new(true, user),
},
key,
})
}

Expand Down

0 comments on commit 9bfec97

Please sign in to comment.