Function basenc::encode
[−]
[src]
pub fn encode<C: Encoding, B: EncodeBuf>(
bytes: &[u8],
encoding: C,
buffer: B
) -> B::Output
Directly encode into an encode buffer.
Convenient as it doesn't require the Encoding
trait to be imported.
Note that encoding can never fail.
Examples
assert_eq!( basenc::encode(b"hello world", basenc::Base64Std, String::new()), "aGVsbG8gd29ybGQ=" );
Convenience, appends to a by-value buffer and returns that buffer.
let mut str_buf = String::from("output: "); assert_eq!( basenc::encode(b"BuFfEr ReUsE!", basenc::Base64Url, &mut str_buf), "QnVGZkVyIFJlVXNFIQ" ); assert_eq!(str_buf, "output: QnVGZkVyIFJlVXNFIQ");
Appends to an existing buffer, returns a reference to the encoded input.
let mut stack_buf = [0u8; 16]; assert_eq!( basenc::encode(b"\x00\x80\xFF\xDC", basenc::LowerHex, &mut stack_buf[..]), "0080ffdc" );
Uses fixed-size arrays on the stack as a buffer, available with #[no_std]
.
Panics if the buffer is too small to fit the output.