pub struct Type(/* private fields */);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..=0xFFImplementations§
Source§impl Type
impl Type
Sourcepub unsafe fn new_unchecked(code: impl AsRef<[u8]>) -> Self
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.
Sourcepub fn into_inner(self) -> SmallVec<[u8; 16]>
pub fn into_inner(self) -> SmallVec<[u8; 16]>
Returns the inner type code which is a sequence of type codes by consuming the type.
Sourcepub fn lambda<I>(
params: I,
variadic: Option<Self>,
ret: Self,
) -> Result<Self, TypeError>where
I: IntoIterator<Item = Self>,
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.
Sourcepub fn as_lambda(&self) -> Option<LambdaType>
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.
Sourcepub fn option(ty: Self) -> Result<Self, TypeError>
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.
Sourcepub fn as_option(&self) -> Option<OptionType>
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.
Sourcepub fn pair(car: Self, cdr: Self) -> Result<Self, TypeError>
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.
Sourcepub fn union<I>(types: I) -> Result<Self, TypeError>where
I: IntoIterator<Item = Self>,
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.
Sourcepub fn is_specific(&self) -> bool
pub fn is_specific(&self) -> bool
Returns true if the type is a specific type.