-
Notifications
You must be signed in to change notification settings - Fork 11
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
Adds push_with
method
#10
Conversation
Co-authored-by: Ibraheem Ahmed <[email protected]>
src/raw.rs
Outdated
F: FnOnce(usize) -> T, | ||
{ | ||
let index = self.next_index(); | ||
let value = f(index - 1); |
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 why the subtraction here?
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.
🤦♂️
/// ``` | ||
/// let vec = boxcar::vec![0, 1]; | ||
/// vec.push_with(|index| index + 1); | ||
/// assert_eq!(vec, [0, 1, 2]); |
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 think this is incorrect due to above? It was inserted into index 2
, so the value of the element should be 3
.
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.
Oh boy, i goofed that entirely.
I think I was trying to figure out what the debug output of (_, _)
was, added + 1
there and then promptly forgot about it (the + 1
). I later added - 1
to get the test to pass 🤦♂️ .
ugh, that's quiet embarrassing. Sorry about that. It should be fixed now.
Nice, thanks! |
Adds
push_with
, allowing forT
to be produced by a closure which is passed the index of the element.Resolves #9.