Struct data_encoding::Builder [] [src]

pub struct Builder {
    pub symbols: Box<[u8]>,
    pub values: Box<Array128>,
    pub bit_order: BitOrder,
    pub padding: Option<u8>,
    pub check_trailing_bits: bool,
}

Base representation

Convenience methods are provided to edit the fields, although they may be manually edited.

Examples

See the lower-case hexadecimal, upper-case hexadecimal, lower-case permissive hexadecimal, base32, base32hex, base64, and base64url encodings.

Fields

Symbols

The number of symbols must be 2, 4, 8, 16, 32, or 64. Symbols must be ASCII characters (smaller than 128) and they must be unique.

Values

A value of 128 means that the index is not a symbol. In other words, if values[s] != 128 then s is a symbol (canonical if symbols[values[s]] is equal to s) and values[s] is its value.

Default is the inverse of symbols.

Bit-order

Default is most significant bit first.

Padding

Default is no padding.

Whether trailing bits are checked

Default is to check trailing bits. This field is ignored when unnecessary (i.e. for base2, base4, and base16).

Methods

impl Builder
[src]

Returns a canonical base representation for symbols

By default, the base representation does not have non-canonical symbols. It does not have padding. It is most significant bit first. And it checks the trailing bits if necessary.

Errors

Errors are silently ignored. In other words, if a symbol is not ASCII, if there are duplicate symbols, or if the number of symbols is not a power of 2 smaller than 128, then no errors are signaled. However, when building the base with no_pad or padded, if the base representation is still invalid, an error will be returned.

Sets padding

Adds non-canonical symbols

For all i, from[i] is given the same value as to[i].

By default there are only canonical symbols. Non-canonical symbols cannot be produced by encoding functions, but they are recognized by decoding functions. They behave as the canonical symbol of the same value.

Panics

Panics if from and to don't have the same length.

Errors

Errors are silently ignored. If a character in from or to is not ASCII then the pair is skipped. If the character in from is already a symbol it is overwritten. If the character in to is not a symbol, from is reset.

Examples

let base = Builder::new(b"0123456789abcdef")
    .translate(b"ABCDEF", b"abcdef").no_pad().unwrap();
assert_eq!(base.decode(b"Bb").unwrap(), vec![0xbb]);

Sets bit-order to least significant bit first

Ignores trailing bits

Returns the represented base-conversion encoding

Errors

Returns an error if the base representation is invalid.

Returns the represented padded base-conversion encoding

Errors

Returns an error if the base representation is invalid.

Trait Implementations

impl Debug for Builder
[src]

Formats the value using the given formatter.

impl Clone for Builder
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a> From<&'a NoPad> for Builder
[src]

Performs the conversion.

impl<'a> From<&'a Padded> for Builder
[src]

Performs the conversion.