-
Notifications
You must be signed in to change notification settings - Fork 7
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
Implement Iterator trait for Fragment and BoundedVec #327
Conversation
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.
What about bytes_to_nibbles function? I think there are a few similar places. I understand that we need i
in these situations, but maybe we can add additional counter? Let's check if it would look better or worse
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 approve after discussing offline my previous comment :)
bounded_vec.for_each(|x| result.push(f(x))); | ||
|
||
*result | ||
} |
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.
Idea:
impl<T, N> Iterator<T> for BoundedVec<T, N> {
fn map<Env, R>(self, f: fn[Env](T) -> R) -> Iterator<R> {
...
}
}
@@ -1,3 +1,5 @@ | |||
use crate::misc::iterator::Iterator; | |||
|
|||
pub fn bounded_vec_from_array<T, N, M>(array: [T; N]) -> BoundedVec<T, M> { |
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.
Can we do it as From
trait?
} | ||
|
||
impl<T, N> Iterator<T> for BoundedVec<T, N> { | ||
fn for_each<Env>(self, f: fn[Env](T) -> ()) { |
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.
-> each
This PR creates Iterator trait with one function:
for_each
and implements it for Fragment and BoundedVec.It also migrates the code to use
for_each
where possible. I only found 2 places (1 for Fragment and 1 for BoundedVec) where it's possible to use it. In the rest of the loops iterating over fragments or boundedvecsi
(loop iterator) is used in some way that makes it impossible to usefor_each
.