Function scolapasta_hex::try_encode

source ·
pub fn try_encode<T: AsRef<[u8]>>(data: T) -> Result<String, TryReserveError>
Available on crate feature alloc only.
Expand description

Encode arbitrary octets as base16. Returns a String.

This function allocates an empty String and delegates to try_encode_into.

§Errors

If the allocated string’s capacity overflows, or the allocator reports a failure, then an error is returned.

§Examples

let data = b"Artichoke Ruby";
let buf = scolapasta_hex::try_encode(data)?;
assert_eq!(buf, "4172746963686f6b652052756279");