Struct arithmetic_typing::FunctionBuilder
source · 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>
impl<Prim: PrimitiveType> FunctionBuilder<Prim>
Trait Implementations§
source§impl<Prim: Clone + PrimitiveType> Clone for FunctionBuilder<Prim>
impl<Prim: Clone + PrimitiveType> Clone for FunctionBuilder<Prim>
source§fn clone(&self) -> FunctionBuilder<Prim>
fn clone(&self) -> FunctionBuilder<Prim>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<Prim: Debug + PrimitiveType> Debug for FunctionBuilder<Prim>
impl<Prim: Debug + PrimitiveType> Debug for FunctionBuilder<Prim>
source§impl<Prim: PrimitiveType> Default for FunctionBuilder<Prim>
impl<Prim: PrimitiveType> Default for FunctionBuilder<Prim>
Auto Trait Implementations§
impl<Prim> Freeze for FunctionBuilder<Prim>
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> 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
Mutably borrows from an owned value. Read more
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)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)