Open ExpHP opened 4 years ago
you could replace the closure like this:
|bytes: &[u8]| match bytes[0] {
b'n' => &b"\n"[..],
_ => &bytes[..1],
}
Okay, this is true, you can use static references if there are only a limited number of escapes.
Is there any particular reason why u8
and Vec<u8>
do not implement the trait? They would provide additional power by allowing the values to be constructed at runtime, making it easier to support escapes like "\xXX"
for an arbitrary byte. (I think this can be done with static refs but it's a bit janky, as it requires having a static string with all byte values like b"\x00\x01\x02\x03...\xfe\xff"
to take slices from)
It is unclear to me how to use
bytes::complete::escape_transform
on bytestrings, because the only implementors ofExtendInto<Extender=Vec<u8>>
are[u8]
and&[u8]
, neither of which can be returned without borrowing from the input.rustc 1.46.0
Test case