pub struct Segment<Args, Stack = <<Args as IntoList>::Output<CNil<()>> as List>::ReverseOnto<<<Args as IntoList>::Output<CNil<()>> as List>::Empty>>{ /* private fields */ }Expand description
A type-safe segment that represents a sequence of operations.
The segment takes input arguments of type Args and maintains a type stack Stack that tracks
the types of values produced by operations.
§Type Parameters
Args: The input argument types, must implementIntoListStack: The type stack tracking operation results, defaults to the reverse ofArgs
§Examples
use cel_runtime::segment::*;
assert_eq!(Segment::<(i32,)>::new() // create a new segment that takes an i32 argument
.op1(|x| x * 2) // push a unary operation that multiplies the argument by 2
.op0(|| 10) // push a nullary operation that returns 10
.op2(|x, y| x + y) // push a binary operation that adds two arguments
.op1(|x| x.to_string()) // push a unary operation returning a string of the argument
.call((42, )).unwrap(), // call the segment with an argument 42
"94"); // the result is (42 * 2 + 10).to_string()Implementations§
Source§impl<Args, Stack> Segment<Args, Stack>where
Args: IntoList + 'static,
Stack: StackResult + 'static,
<Stack as List>::Tail: CStackListHeadLimit,
impl<Args, Stack> Segment<Args, Stack>where
Args: IntoList + 'static,
Stack: StackResult + 'static,
<Stack as List>::Tail: CStackListHeadLimit,
Sourcepub fn op0<R, F>(self, op: F) -> Segment<Args, <Stack as List>::Push<R>>where
F: Fn() -> R + 'static,
R: 'static,
pub fn op0<R, F>(self, op: F) -> Segment<Args, <Stack as List>::Push<R>>where
F: Fn() -> R + 'static,
R: 'static,
Pushes a nullary operation that takes no arguments and returns a value of type R.
Sourcepub fn op0r<R, F>(self, op: F) -> Segment<Args, <Stack as List>::Push<R>>
pub fn op0r<R, F>(self, op: F) -> Segment<Args, <Stack as List>::Push<R>>
Pushes a fallible nullary operation that returns Result<R>.
Sourcepub fn op1<R, F>(
self,
op: F,
) -> Segment<Args, CStackList<R, <Stack as List>::Tail>>
pub fn op1<R, F>( self, op: F, ) -> Segment<Args, CStackList<R, <Stack as List>::Tail>>
Pushes a unary operation that takes the current stack value and returns a new value.
Sourcepub fn op1r<R, F>(
self,
op: F,
) -> Segment<Args, CStackList<R, <Stack as List>::Tail>>
pub fn op1r<R, F>( self, op: F, ) -> Segment<Args, CStackList<R, <Stack as List>::Tail>>
Pushes a fallible unary operation that takes the current stack value and returns Result<R>.
Trait Implementations§
Source§impl<T, A, B> SegmentCallable<(A, B)> for Segment<(A, B), T>where
T: StackResult + 'static,
A: 'static,
B: 'static,
<T as List>::Tail: EmptyList + CStackListHeadLimit,
impl<T, A, B> SegmentCallable<(A, B)> for Segment<(A, B), T>where
T: StackResult + 'static,
A: 'static,
B: 'static,
<T as List>::Tail: EmptyList + CStackListHeadLimit,
Source§impl<Args, Stack> TryFrom<DynSegment> for Segment<Args, Stack>
impl<Args, Stack> TryFrom<DynSegment> for Segment<Args, Stack>
Auto Trait Implementations§
impl<Args, Stack> Freeze for Segment<Args, Stack>
impl<Args, Stack> RefUnwindSafe for Segment<Args, Stack>where
Args: RefUnwindSafe,
Stack: RefUnwindSafe,
impl<Args, Stack> Send for Segment<Args, Stack>
impl<Args, Stack> Sync for Segment<Args, Stack>
impl<Args, Stack> Unpin for Segment<Args, Stack>
impl<Args, Stack> UnsafeUnpin for Segment<Args, Stack>
impl<Args, Stack> UnwindSafe for Segment<Args, Stack>where
Args: UnwindSafe,
Stack: UnwindSafe,
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