Skip to main content

Type

Struct Type 

Source
pub struct Type(/* private fields */);
Available on crate feature types only.
Expand description

A type definition.

§Grammar:

The binary representation of a type is a sequence of type codes. The type codes are defined in the code module. The grammar of the type code is defined as follows:

type             = (filled | option | code::VOID | code::NIL) eof
filled           = any | union | specific
specific         = code::TYPE | code::BOOL | code::CHAR | code::INT
                 | code::FLOAT | code::SYMBOL | code::BINARY
                 | array | pair | lambda
filled-or-option = filled | option
array            = code::ARRAY filled-or-option fixed
pair             = code::PAIR filled-or-option filled-or-option
option           = code::OPTION filled
union            = code::UNION specific specific+ code::END
lambda           = code::LAMBDA args varg return
args             = (filled-or-option)*
varg             = (code::VARIADIC filled-or-option)?
return           = code::RETURN (code::VOID | filled-or-option)
fixed            = (fixed0 | fixed1 | fixed2 | fixed3 | fixed4)?
fixed0           = code::FIXED0..=code::FIXED0_MAX
fixed1           = code::FIXED1..=code::FIXED1_MAX byte
fixed2           = code::FIXED2..=code::FIXED2_MAX byte byte
fixed3           = code::FIXED3..=code::FIXED3_MAX byte byte byte
fixed4           = code::FIXED4..=code::FIXED4_MAX byte byte byte byte
byte             = 0x00..=0xFF

Implementations§

Source§

impl Type

Source

pub fn new(code: impl AsRef<[u8]>) -> Result<Self, TypeCodeError>

Creates a new type by parsing the type code.

§Errors

Returns an error if the type code is invalid.

Source

pub unsafe fn new_unchecked(code: impl AsRef<[u8]>) -> Self

Creates a new type by taking the raw code.

§Safety

The type code is taken as is. It is the responsibility of the caller, that the type code is correct.

Source

pub fn into_inner(self) -> SmallVec<[u8; 16]>

Returns the inner type code which is a sequence of type codes by consuming the type.

Source

pub fn array(elem: Self, size: Option<usize>) -> Result<Self, TypeError>

Creates a new array type. If the size is not specified, the array is dynamic.

§Errors

Returns an error if the element type is not filled or an option or if the size is larger than ARRAY_MAX.

Source

pub fn is_array(&self) -> bool

Returns true if the type is an array type.

Source

pub fn as_array(&self) -> Option<ArrayType>

Returns ArrayType if the type is an array type.

§Panics

Panics if the type is a malformed array type. This is a bug and should be reported.

Source

pub fn lambda<I>( params: I, variadic: Option<Self>, ret: Self, ) -> Result<Self, TypeError>
where I: IntoIterator<Item = Self>,

Creates a new lambda type.

§Errors

Returns an error if an parameter type is not filled or an option, if the variadic type is not filled or an option or if the return type is not filled, an option or void.

Source

pub fn is_lambda(&self) -> bool

Returns true if the type is a lambda type.

Source

pub fn as_lambda(&self) -> Option<LambdaType>

Returns LambdaType if the type is a lambda type.

§Panics

Panics if the type is a malformed lambda type. This is a bug and should be reported.

Source

pub fn option(ty: Self) -> Result<Self, TypeError>

Creates a new option type.

§Errors

Returns an error if the inner type is not filled or if the inner type is an option itself.

Source

pub fn is_option(&self) -> bool

Returns true if the type is an option type.

Source

pub fn as_option(&self) -> Option<OptionType>

Returns OptionType if the type is an option type.

§Panics

Panics if the type is a malformed option type. This is a bug and should be reported.

Source

pub fn pair(car: Self, cdr: Self) -> Result<Self, TypeError>

Creates a new pair type.

§Errors

Returns an error if the car or cdr type is not filled or an option.

Source

pub fn is_pair(&self) -> bool

Returns true if the type is a pair type.

Source

pub fn as_pair(&self) -> Option<PairType>

Returns PairType if the type is a pair type.

§Panics

Panics if the type is a malformed pair type. This is a bug and should be reported.

Source

pub fn union<I>(types: I) -> Result<Self, TypeError>
where I: IntoIterator<Item = Self>,

Creates a new union type. The member types must be specific and there must be at least two members.

§Errors

Returns an error if a member type is not specific or if there are less than two members.

Source

pub fn is_union(&self) -> bool

Returns true if the type is a union type.

Source

pub fn as_union(&self) -> Option<UnionType>

Returns UnionType if the type is a union type.

§Panics

Panics if the type is a malformed union type. This is a bug and should be reported.

Source

pub fn is_specific(&self) -> bool

Returns true if the type is a specific type.

Source

pub fn is_filled(&self) -> bool

Returns true if the type is a filled type.

Source

pub fn iter(&self) -> Iter<'_, u8> ⓘ

Returns an iterator over the type code.

Source

pub fn as_slice(&self) -> &[u8] ⓘ

Returns the type code as a slice.

Source§

impl Type

Source

pub fn nil() -> Self

Source

pub fn void() -> Self

Source

pub fn any() -> Self

Source

pub fn typedef() -> Self

Source

pub fn boolean() -> Self

Source

pub fn character() -> Self

Source

pub fn integer() -> Self

Source

pub fn float() -> Self

Source

pub fn string() -> Self

Source

pub fn symbol() -> Self

Source

pub fn binary() -> Self

Source

pub fn vector() -> Self

Source

pub fn list() -> Self

Source

pub fn is_nil(&self) -> bool

Source

pub fn is_void(&self) -> bool

Source

pub fn is_any(&self) -> bool

Source

pub fn is_typedef(&self) -> bool

Source

pub fn is_boolean(&self) -> bool

Source

pub fn is_character(&self) -> bool

Source

pub fn is_integer(&self) -> bool

Source

pub fn is_float(&self) -> bool

Source

pub fn is_string(&self) -> bool

Source

pub fn is_symbol(&self) -> bool

Source

pub fn is_binary(&self) -> bool

Source

pub fn is_vector(&self) -> bool

Source

pub fn is_list(&self) -> bool

Trait Implementations§

Source§

impl AsRef<Type> for Type

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Type

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Type

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Type

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Type

Source§

impl<'a> From<(&Parameters<'a>, &Type)> for Type

Source§

fn from((params, ret): (&Parameters<'a>, &Self)) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Type

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a type from the string. User defined types are not supported, because they cannot be resolved without an environment.

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

impl Hash for Type

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> IntoIterator for &'a Type

Source§

type IntoIter = Iter<'a, u8>

Which kind of iterator are we turning this into?
Source§

type Item = &'a u8

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Type

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<Type> for ArrayType

Source§

fn eq(&self, other: &Type) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<Type> for LambdaType

Source§

fn eq(&self, other: &Type) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<Type> for OptionType

Source§

fn eq(&self, other: &Type) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<Type> for PairType

Source§

fn eq(&self, other: &Type) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<Type> for UnionType

Source§

fn eq(&self, other: &Type) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> Trace<'a> for Type

Source§

fn trace(&self, _: &mut Vec<Root<'a>>)

Auto Trait Implementations§

§

impl Freeze for Type

§

impl RefUnwindSafe for Type

§

impl Send for Type

§

impl Sync for Type

§

impl Unpin for Type

§

impl UnsafeUnpin for Type

§

impl UnwindSafe for Type

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.