Closed lucab closed 3 years ago
I also prefer the current version, which does prevent (unnoticed) trailing bytes
let mut result = [0; 16];
// this would error
hex::encode_to_slice(b"hi", &mut result).unwrap();
// this should be done instead:
hex::encode_to_slice(b"hi", &mut result[..2]).unwrap();
This is especially important, when someone wants to convert the slice to an &str
with str::from_utf8
, which would error if there are trailing zeroes.
Currently,
encode_to_slice
documentation says:However the code checks for an exact size: https://github.com/KokaKiwi/rust-hex/blob/be0c32f9c8938ca0359bbb0d1477e31b07cb3358/src/lib.rs#L349
Which side of the doc-vs-code split should be fixed? (I'm inclined to just clarify the docs, as the resulting/current API is quite ergonomic)