Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update master branch with the changes in Polkadot v1.1.0 #33

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add find method to LimitedVarArray
  • Loading branch information
b-yap committed Aug 5, 2024
commit 630d8cd94afdd4042c0216becf6dae3c25d08b5c
9 changes: 8 additions & 1 deletion src/xdr/compound_types.rs
Original file line number Diff line number Diff line change
@@ -179,6 +179,11 @@ impl<T, const N: i32> LimitedVarArray<T, N> {
pub fn pop(&mut self) -> Option<T> {
self.0.pop()
}

pub fn get_element<P>(&self, mut predicate:P) -> Option<&T>
where P: FnMut(&T) -> bool {
self.0.iter().find(|elem| predicate(elem))
}
}

impl<T: XdrCodec, const N: i32> XdrCodec for LimitedVarArray<T, N> {
@@ -301,12 +306,14 @@ mod tests {
}

#[test]
fn pop_limitedarray() {
fn pop_and_find_limitedarray() {
let sample_vec = vec![0,1,2,3,4];
let mut sample_limited_array = LimitedVarArray::<u8,5>::new(sample_vec).expect("should return just fine");
let len = sample_limited_array.len();
let popped = sample_limited_array.pop();
assert_eq!(popped, Some(4));
assert_ne!(sample_limited_array.len(), len);

assert!(sample_limited_array.get_element(|elem| *elem == 2).is_some());
}
}
Loading