Crate basenc [−] [src]
BaseNC
Encoding and decoding of Base-N encodings, #[no_std]
compatible.
Encoding trait
The hero of the show is Encoding
, defining the entry point for encoding and decoding for an encoding.
The trait is implemented by unit structs, eg. Base64Std
, allowing type inference to help out.
The hero has two sidekicks: Encoder
and Decoder
providing access to the encoding's iterator adapters.
Buffer to buffer
When you have an input buffer, &[u8]
or &str
, and want to encode or decode respectively to a new buffer
can be done conveniently using the encode
and decode
free functions.
They are ensured to be implemented efficiently and avoid code bloat.
Buffers
A side note about buffers, they are types implementing the EncodeBuf
and DecodeBuf
traits.
Under #[no_std]
they are only implemented by &mut [u8]
acting as a fixed size buffer.
Otherwise EncodeBuf
is implemented by String
for convenience and &mut String
and &mut Vec<u8>
for efficient buffer reuse.
DecodeBuf
is implemented by Vec<u8>
for convenience and &mut Vec<u8>
for efficient buffer reuse.
Iterator adapters
For maximum flexibility the encoding and decoding can be pipelined as an iterator adapter.
The trait Encode
adapts an iterator over bytes given an encoding into an iterator over chars of the encoded input.
The trait Decode
adapts an iterator over chars given an encoding into an iterator over the resulting bytes of the decoded input.
Structs
AnyHex |
Hex charset using lower-case letters. |
Base64Std |
Base64 standard charset. |
Base64Url |
Base64 url-safe charset. |
LowerHex |
Hex charset using strictly lower-case letters. |
UpperHex |
Hex charset using strictly upper-case letters. |
Enums
Error |
Decoding error. |
Traits
Decode |
Char iterator adapter to a decoder. |
DecodeBuf |
Byte buffer receiving decoded input. |
Decoder |
Create a decoder adapter for an encoding given an |
Encode |
Byte iterator adapter to an encoder. |
EncodeBuf |
String buffer receiving encoded input. |
Encoder |
Create an encoder adapter for an encoding given an |
Encoding |
Data encoding. |
Functions
decode |
Directly decode into a decode buffer. |
encode |
Directly encode into an encode buffer. |