pub const fn new(base: &[u8; 58]) -> Result<Self, Error> {
        let mut encode = [0x00; 58];
        let mut decode = [0xFF; 128];

        let mut i = 0;
        while i < encode.len() {
            if base[i] >= 128 {
                return Err(Error::NonAsciiCharacter { index: i });
            }
            if decode[base[i] as usize] != 0xFF {
                return Err(Error::DuplicateCharacter {
                    character: base[i] as char,
                    first: decode[base[i] as usize] as usize,
                    second: i,
                });
            }
            encode[i] = base[i];
            decode[base[i] as usize] = i as u8;
            i += 1;
        }

        Ok(Self { encode, decode })
    }
/// Create prepared alphabet, checks that the alphabet is pure ASCII and that there are no
/// duplicate characters, which would result in inconsistent encoding/decoding
///
/// ```rust
/// let alpha = bs58::Alphabet::new(
///     b" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY"
/// )?;
///
/// let decoded = bs58::decode("he11owor1d")
///     .with_alphabet(bs58::Alphabet::RIPPLE)
///     .into_vec()?;
/// let encoded = bs58::encode(decoded)
///     .with_alphabet(&alpha)
///     .into_string();
///
/// assert_eq!("#ERRN)N RD", encoded);
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// ## Errors
///
/// ### Duplicate Character
///
/// ```rust
/// let alpha = b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
/// assert_eq!(
///     bs58::alphabet::Error::DuplicateCharacter { character: 'a', first: 0, second: 1 },
///     bs58::Alphabet::new(alpha).unwrap_err());
/// ```
///
/// ### Non-ASCII Character
///
/// ```rust
/// let mut alpha = *b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
/// alpha[1] = 255;
/// assert_eq!(
///     bs58::alphabet::Error::NonAsciiCharacter { index: 1 },
///     bs58::Alphabet::new(&alpha).unwrap_err());
/// ```
Create prepared alphabet, checks that the alphabet is pure ASCII and that there are no
duplicate characters, which would result in inconsistent encoding/decoding






Create prepared alphabet checks that the alphabet is pure ASCII and that there are no duplicate characters which would result in inconsistent encoding / decoding
pub const fn new(base: &[u8; 58]) -> Result<Self, Error> {
        let mut encode = [0x00; 58];
        let mut decode = [0xFF; 128];
        let mut i = 0;
        while i < encode.len() {
            if base[i] >= 128 {
                return Err(Error::NonAsciiCharacter { index: i });
            }
            if decode[base[i] as usize] != 0xFF {
                return Err(Error::DuplicateCharacter {
                    character: base[i] as char,
                    first: decode[base[i] as usize] as usize,
                    second: i,
                });
            }
            encode[i] = base[i];
            decode[base[i] as usize] = i as u8;
            i += 1;
        }
        Ok(Self { encode, decode })
    }
pub const fn new ( base : & [ u8 ; 58 ] ) -> Result < Self , Error > { let mut encode = [ 0x00 ; 58 ] ; let mut decode = [ 0xFF ; 128 ] ; let mut i = 0 ; while i < encode . len ( ) { if base [ i ] >= 128 { return Err ( Error :: NonAsciiCharacter { index : i } ) ; } if decode [ base [ i ] as usize ] != 0xFF { return Err ( Error :: DuplicateCharacter { character : base [ i ] as char , first : decode [ base [ i ] as usize ] as usize , second : i , } ) ; } encode [ i ] = base [ i ] ; decode [ base [ i ] as usize ] = i as u8 ; i += 1 ; } Ok ( Self { encode , decode } ) }
Create prepared alphabet, checks that the alphabet is pure ASCII and that there are no
duplicate characters, which would result in inconsistent encoding/decoding
Create prepared alphabet checks that the alphabet is pure ASCII and that there are no duplicate characters which would result in inconsistent encoding / decoding
base
&[u8; 58]
base
&[u8; 58]
ok::<(), box<dyn std::error::error>>(())
None
errors
None
duplicate character
None
non-ascii character
None