Crate basenc

Source
Expand description

§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§

  • Hex charset using lower-case letters.
  • Base64 standard charset.
  • Base64 url-safe charset.
  • Hex charset using strictly lower-case letters.
  • Hex charset using strictly upper-case letters.

Enums§

Traits§

  • Char iterator adapter to a decoder.
  • Byte buffer receiving decoded input.
  • Create a decoder adapter for an encoding given an Iterator<Item = char>.
  • Byte iterator adapter to an encoder.
  • String buffer receiving encoded input.
  • Create an encoder adapter for an encoding given an Iterator<Item = u8>.
  • Data encoding.

Functions§

  • Directly decode into a decode buffer.
  • Directly encode into an encode buffer.