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
203 stars 57 forks source link

Add `encode_to` API #66

Open cgwalters opened 2 years ago

cgwalters commented 2 years ago

In https://github.com/ostreedev/ostree-rs-ext/ we are performing hex encoding in loops and recursively, and it could be helpful for performance to support re-using a buffer instead of allocating a new String on the heap.

Currently we are using encode_to_slice, but then we need to use e.g. std::str::from_utf8 which unnecessarily performs UTF-8 validation and is also hence fallible even though it doesn't need to be.

cgwalters commented 2 years ago

Another alternative is to just make BytesToHexChars public.

cgwalters commented 2 years ago

OK this is also much cleaner using String::extend and even better will honor the size hint.

cgwalters commented 2 years ago

I rolled in https://github.com/KokaKiwi/rust-hex/pull/67 here.