Trait bcder::string::CharSet

source ·
pub trait CharSet {
    const TAG: Tag;

    // Required methods
    fn next_char<I: Iterator<Item = u8>>(
        iter: &mut I
    ) -> Result<Option<char>, CharSetError>;
    fn from_str(s: &str) -> Result<Cow<'_, [u8]>, CharSetError>;

    // Provided method
    fn check<I: Iterator<Item = u8>>(iter: &mut I) -> Result<(), CharSetError> { ... }
}
Expand description

The character set of a restricted character string type.

The trait only includes associated functions and can thus be implemented for marker types. It main purpose is to take an iterator over u8s and produce chars or errors. This happens in next_char.

The trait is primarily used to define the character set of the RestrictedString type.

Required Associated Constants§

source

const TAG: Tag

The natural tag of the related restricted character string type.

Required Methods§

source

fn next_char<I: Iterator<Item = u8>>( iter: &mut I ) -> Result<Option<char>, CharSetError>

Returns the next character from a octet sequence.

source

fn from_str(s: &str) -> Result<Cow<'_, [u8]>, CharSetError>

Converts a str into a octet sequence.

The method takes a str and converts it into one of three things. If the string can be encoded in this character set and its own octet sequence is identical to the encoded sequence, it returns its octet sequence as a Ok(Cow::Borrowed(_)). If the octet sequence differs, it creates that and returns it as a Ok(Cow::Owned(_)). Finally, if the string cannot be encoded in this character set, it returns an error.

Provided Methods§

source

fn check<I: Iterator<Item = u8>>(iter: &mut I) -> Result<(), CharSetError>

Checks whether a sequence of octets is a valid string.

The method returns an error if the sequence of the octets represented by iter is not in fact a valid string for this character set.

Object Safety§

This trait is not object safe.

Implementors§