pub struct FunctionBuilder<Prim: PrimitiveType = Num> { /* private fields */ }
Expand description

Builder for functional types.

Tip. You may also use FromStr implementation to parse functional types.

Examples

Signature for a function summing a slice of numbers:

let sum_fn_type = Function::builder()
    .with_arg(Type::NUM.repeat(UnknownLen::param(0)))
    .returning(Type::NUM);
assert_eq!(sum_fn_type.to_string(), "([Num; N]) -> Num");

Signature for a slice mapping function:

// Definition of the mapping arg.
let map_fn_arg = <Function>::builder()
    .with_arg(Type::param(0))
    .returning(Type::param(1));

let map_fn_type = <Function>::builder()
    .with_arg(Type::param(0).repeat(UnknownLen::param(0)))
    .with_arg(map_fn_arg)
    .returning(Type::param(1).repeat(UnknownLen::Dynamic))
    .with_constraints(&[1], Linearity);
assert_eq!(
    map_fn_type.to_string(),
    "for<'U: Lin> (['T; N], ('T) -> 'U) -> ['U]"
);

Signature of a function with varargs:

let fn_type = <Function>::builder()
    .with_varargs(Type::param(0), UnknownLen::param(0))
    .with_arg(Type::BOOL)
    .returning(Type::param(0));
assert_eq!(fn_type.to_string(), "(...['T; N], Bool) -> 'T");

Implementations§

source§

impl<Prim: PrimitiveType> FunctionBuilder<Prim>

source

pub fn with_arg(self, arg: impl Into<Type<Prim>>) -> Self

Adds a new argument to the function definition.

source

pub fn with_varargs( self, element: impl Into<Type<Prim>>, len: impl Into<TupleLen> ) -> Self

Adds or sets varargs in the function definition.

source

pub fn returning(self, return_type: impl Into<Type<Prim>>) -> Function<Prim>

Declares the return type of the function and builds it.

Trait Implementations§

source§

impl<Prim: Clone + PrimitiveType> Clone for FunctionBuilder<Prim>

source§

fn clone(&self) -> FunctionBuilder<Prim>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<Prim: Debug + PrimitiveType> Debug for FunctionBuilder<Prim>

source§

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

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

impl<Prim: PrimitiveType> Default for FunctionBuilder<Prim>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Prim = Num> !RefUnwindSafe for FunctionBuilder<Prim>

§

impl<Prim> Send for FunctionBuilder<Prim>

§

impl<Prim> Sync for FunctionBuilder<Prim>

§

impl<Prim> Unpin for FunctionBuilder<Prim>where Prim: Unpin,

§

impl<Prim = Num> !UnwindSafe for FunctionBuilder<Prim>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.