Skip to main content

Character

Trait Character 

Source
pub trait Character:
    Sized
    + Eq
    + Copy
    + Display
    + Debug
    + From<u8>
    + TryInto<u8>
    + TryFrom<u64>
    + Into<u64>
    + Ord
    + Hash
    + Default
    + 'static {
    type CharMap<A: Clone + Default>: CharacterMap<Self, A>;
    type Iter<'a>: ExactSizeIterator<Item = Self>;

    const MIN: Self;
    const MAX: Self;

    // Required methods
    fn convert(input: Vec<u8>) -> TextLine<Self>;
    fn display_fmt<W: Write>(&self, target: &mut W);
    fn to_char(&self) -> char;
    fn starting_catcode_scheme() -> CategoryCodeScheme<Self>;
    fn string_to_iter(string: &str) -> Self::Iter<'_>;

    // Provided methods
    fn display(&self) -> DisplayableCharacter<Self> { ... }
    fn display_opt(c: Option<Self>) -> DisplayableCharacterOpt<Self> { ... }
}
Expand description

A single character in a .tex file; in plain TeX, this is a u8, but in e.g. XeTeX, it is a UTF-8 character.

Required Associated Constants§

Source

const MIN: Self

minimal value of this type in numeric form (e.g. 0 for u8)

Source

const MAX: Self

maximal value of this type in numeric form (e.g. 255 for u8)

Required Associated Types§

Source

type CharMap<A: Clone + Default>: CharacterMap<Self, A>

Type that maps characters to other data.

Source

type Iter<'a>: ExactSizeIterator<Item = Self>

Iterator over characters in a string.

Required Methods§

Source

fn convert(input: Vec<u8>) -> TextLine<Self>

Convert a line in a file/string (as a vector of bytes) into a Vec of Characters.

Source

fn display_fmt<W: Write>(&self, target: &mut W)

Display this character to a Write (e.g. a &mut String). Relevant for e.g. TeX’s convention to display control characters using ^^ encoding.

Source

fn to_char(&self) -> char

Convert this character to a char.

Source

fn starting_catcode_scheme() -> CategoryCodeScheme<Self>

The starting CategoryCodeScheme for this character type.

Source

fn string_to_iter(string: &str) -> Self::Iter<'_>

Convert a string to an iterator over characters.

Provided Methods§

Source

fn display(&self) -> DisplayableCharacter<Self>

Convert this character to a DisplayableCharacter that calls display; useful in format! and write! macros.

Source

fn display_opt(c: Option<Self>) -> DisplayableCharacterOpt<Self>

Like display, but for an Option<Character>. Useful for format! and write! macros specifically for the current \ecapechar (which may or may not be defined).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Character for u8

Source§

const MIN: Self = 0

Source§

const MAX: Self = 255

Source§

type CharMap<A: Clone + Default> = [A; 256]

Source§

type Iter<'a> = ByteIterator<'a>

Source§

fn to_char(&self) -> char

Source§

fn string_to_iter(string: &str) -> Self::Iter<'_>

Source§

fn convert(input: Vec<u8>) -> TextLine<Self>

Source§

fn display_fmt<W: Write>(&self, target: &mut W)

Source§

fn starting_catcode_scheme() -> [CategoryCode; 256]

Implementors§