-
Notifications
You must be signed in to change notification settings - Fork 228
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
Add set_name and clear_attributes functions to BytesStart #149
Conversation
Those |
6fb495f
to
9b1cefd
Compare
Thanks ;) that's been taking care of. |
@tafia looks like the Travis failure is just |
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.
Looks great.
Could you just amend the comment to avoid confusion?
Thanks for the PR and sorry for the late response. |
d3cf373
to
85d74b0
Compare
Last change made me think that perhaps /// Edit the name of the BytesStart in-place
pub fn set_name(&mut self, name: &[u8]) -> &mut BytesStart<'a> {
{
let bytes = self.buf.to_mut();
bytes.splice(..self.name_len, name.to_vec());
}
self.name_len = name.len();
self
} |
Sounds better indeed! |
85d74b0
to
171814d
Compare
Done, I feel like this can be merged |
Thanks! |
pub fn set_name(&mut self, name: &[u8]) -> &mut BytesStart<'a> { | ||
{ | ||
let bytes = self.buf.to_mut(); | ||
bytes.splice(..self.name_len, name.to_vec()); |
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.
@meven I don't think the to_vec
call here is needed. It'd be good to avoid the extra allocation!
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 did not find a better way I would expect the same but I ran into
error[E0271]: type mismatch resolving `<&[u8] as std::iter::IntoIterator>::Item == u8`
--> src/events/mod.rs:178:19
|
178 | bytes.splice(..self.name_len, name);
| ^^^^^^ expected reference, found u8
|
= note: expected type `&u8`
found type `u8`
It seems I still need some conversion, name &[u8]
implements IntoIterator<u8>
but I need an IntoIterator<&u8>
. Maybe There is some simple trick I am missing.
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.
Ah, I've run into this in the past. It's a little silly. Basically what you want is name.iter().cloned()
or name.iter().map(|&b| b)
to tell the compiler that you want to utilize the fact that u8
is Copy
.
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.
Thanks, will make another PR
Fixes #148