pub fn encode_alternative_bytes<T: Into<u128>>(
num: T,
buf: &mut [u8],
) -> Result<usize, EncodeError>
Expand description
Encodes an unsigned integer into base62, using the alternative digit ordering (0 to 9, then a to z, then A to Z), and writes it to the passed buffer.
The return value is the number of bytes written to the buffer.
§Safety
- To encode all possible values of u128, the buffer must be at least 22 bytes long. However a smaller buffer may be used if the value to be encoded is known to be smaller. Base62 encoding adds 37.5% overhead to the size of the input.
- The remaining end of the buffer is left untouched. It’s up to the caller to zero it using the returned len if they want to.
§Example
extern crate base62;
let mut buf = [0; 22];
base62::encode_bytes(1337_u32, &mut buf);
assert_eq!(&buf[..2], b"LZ");