-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Allow members of groups to change their key #4300
Conversation
let mut members = <Members<T, I>>::get(); | ||
let location = members.binary_search(&remove).ok().ok_or("not a member")?; | ||
members[location] = new.clone(); | ||
let _location = members.binary_search(&new).err().ok_or("already a member")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, shouldn't this be performed after sorting?
After removed
gets replaced with new
the Vec
is not necessarily sorted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm? The vector is sorted after inserting the new key?
When you insert the new key, the sorting is very likely not the same as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed that the let _location = members.binary_search(&new).err().ok_or("already a member")?;
expected it be an error sorry about that.
I still find Err(already a member)
confusing because if got [10, 20, 30]
and want to replace 30 -> 40
it will end up in error: already a member
Am I misunderstanding something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yeah! Fuck that is right, we should search before inserting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, now I understand why the test works. Yep, that is an error.
let mut members = <Members<T, I>>::get(); | ||
let location = members.binary_search(&remove).ok().ok_or("not a member")?; | ||
members[location] = new.clone(); | ||
let _location = members.binary_search(&new).err().ok_or("already a member")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm? The vector is sorted after inserting the new key?
When you insert the new key, the sorting is very likely not the same as before.
No description provided.