KokaKiwi / rust-hex

A basic crate to encode values to hexadecimal representation. Originally extracted from rustc-serialize.
https://crates.io/crates/hex
Apache License 2.0
201 stars 55 forks source link

Have encode_to_slice() return a &mut str and add encode_fmt #74

Open coolreader18 opened 1 year ago

coolreader18 commented 1 year ago

Also some internal changes that I think make stuff more efficient.

A lot of the times I have a fixed length byte buffer to encode, but cause encode_to_slice doesn't give you access to a str you have to do a check or use unsafe to turn it into a str. This makes it like char::encode_utf8(), where you encode into a buffer and then get to actually use the string from it right away. Also encode_fmt is nice for if something's in a Display/Debug implementation, or just if it's not necessary to allocate a whole separate string.