Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Types

This section is a work-in-progress experiment about making the book executable.

Syntax
Type:
    | bool => Type::Bool
    | str => Type::Str
    | ( types=TupleTypes? ) => Type::Tuple(types.unwrap_or_default())
    | Self => Type::TraitSelf
    | & lifetime=Lifetime? m=Mutability ty=Type => Type::Ref(lifetime, m, Box::new(ty))
TupleTypes: types=( Type , )+ last=Type?
    => types.into_iter().chain(last).collect()

pub enum Type {
    Bool,
    Str,
    Tuple(Vec<Type>),
    TraitSelf,
    Ref(Option<Lifetime>, Mutability, Box<Type>),
}

impl Type {
    pub fn mk_unit() -> Type {
        Type::Tuple(Vec::new())
    }
}