Struct arithmetic_typing::Function 
source · pub struct Function<Prim: PrimitiveType = Num> { /* private fields */ }Expand description
Functional type.
§Notation
Functional types are denoted as follows:
for<len! M; 'T: Lin> (['T; N], 'T) -> ['T; M]
Here:
len! Mand'T: Linare constraints on length params and type params, respectively. Length and/or type params constraints may be empty. Unconstrained type / length params (such as lengthNin the example) do not need to be mentioned.len! Mmeans thatMis a static length.Linis a constraint on the type param.N,Mand'Tare parameter names. The args and the return type may reference these parameters.['T; N]and'Tare types of the function arguments.['T; M]is the return type.
The for constraints can only be present on top-level functions, but not in functions
mentioned in args / return types of other functions.
The -> _ part is mandatory, even if the function returns Type::void().
A function may accept variable number of arguments of the same type along
with other args. (This construction is known as varargs.) This is denoted similarly
to middles in Tuples. For example, (...[Num; N]) -> Num denotes a function
that accepts any number of Num args and returns a Num value.
§Construction
Functional types can be constructed via Self::builder() or parsed from a string.
With Self::builder(), type / length params are implicit; they are computed automatically
when a function or FnWithConstraints is supplied to a TypeEnvironment. Computations
include both the function itself, and any child functions.
§Examples
let fn_type: Function = FunctionAst::try_from("([Num; N]) -> Num")?
    .try_convert()?;
assert_eq!(*fn_type.return_type(), Type::NUM);
assert_matches!(
    fn_type.args().parts(),
    ([Type::Tuple(t)], None, [])
        if t.as_slice().map(Slice::element) == Some(&Type::NUM)
);Implementations§
source§impl<Prim: PrimitiveType> Function<Prim>
 
impl<Prim: PrimitiveType> Function<Prim>
sourcepub fn builder() -> FunctionBuilder<Prim>
 
pub fn builder() -> FunctionBuilder<Prim>
Returns a builder for Functions.
sourcepub fn return_type(&self) -> &Type<Prim>
 
pub fn return_type(&self) -> &Type<Prim>
Gets the return type of this function.
sourcepub fn is_concrete(&self) -> bool
 
pub fn is_concrete(&self) -> bool
Returns true iff this type does not contain type / length variables.
See TypeEnvironment for caveats of dealing with
non-concrete types.
sourcepub fn with_constraints<C: Constraint<Prim>>(
    self,
    indexes: &[usize],
    constraint: C,
) -> FnWithConstraints<Prim>
 
pub fn with_constraints<C: Constraint<Prim>>( self, indexes: &[usize], constraint: C, ) -> FnWithConstraints<Prim>
Marks type params with the specified indexes to have constraints.
§Panics
- Panics if parameters were already computed for the function.
 
sourcepub fn with_static_lengths(self, indexes: &[usize]) -> FnWithConstraints<Prim>
 
pub fn with_static_lengths(self, indexes: &[usize]) -> FnWithConstraints<Prim>
Marks lengths with the specified indexes as static.
§Panics
- Panics if parameters were already computed for the function.
 
Trait Implementations§
source§impl<Prim: PrimitiveType> Display for Function<Prim>
 
impl<Prim: PrimitiveType> Display for Function<Prim>
source§impl<Prim: PrimitiveType> From<FnWithConstraints<Prim>> for Function<Prim>
 
impl<Prim: PrimitiveType> From<FnWithConstraints<Prim>> for Function<Prim>
source§fn from(value: FnWithConstraints<Prim>) -> Self
 
fn from(value: FnWithConstraints<Prim>) -> Self
source§impl<Prim: PartialEq + PrimitiveType> PartialEq for Function<Prim>
 
impl<Prim: PartialEq + PrimitiveType> PartialEq for Function<Prim>
impl<Prim: PrimitiveType> StructuralPartialEq for Function<Prim>
Auto Trait Implementations§
impl<Prim> Freeze for Function<Prim>where
    Prim: Freeze,
impl<Prim = Num> !RefUnwindSafe for Function<Prim>
impl<Prim> Send for Function<Prim>
impl<Prim> Sync for Function<Prim>
impl<Prim> Unpin for Function<Prim>where
    Prim: Unpin,
impl<Prim = Num> !UnwindSafe for Function<Prim>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
 
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)