pub struct ConditionalRouter { /* private fields */ }Expand description
A filter node that routes frames to one of two output ports based on a predicate function applied to each incoming frame.
- Output port 0: condition is
true - Output port 1: condition is
false
Implementations§
Source§impl ConditionalRouter
impl ConditionalRouter
Sourcepub fn new(condition: Box<dyn Fn(&FilterFrame) -> bool + Send + Sync>) -> Self
pub fn new(condition: Box<dyn Fn(&FilterFrame) -> bool + Send + Sync>) -> Self
Create a new conditional router with the given predicate.
The predicate receives a shared reference to the frame and returns
true to route to output 0 or false to route to output 1.
Sourcepub fn last_route(&self) -> Option<u32>
pub fn last_route(&self) -> Option<u32>
Return which output port the last frame was routed to.
Sourcepub fn route(&self, frame: &FilterFrame) -> u32
pub fn route(&self, frame: &FilterFrame) -> u32
Evaluate the condition and return the output port index (0 or 1).
Trait Implementations§
Source§impl Node for ConditionalRouter
impl Node for ConditionalRouter
Source§fn outputs(&self) -> &[OutputPort]
fn outputs(&self) -> &[OutputPort]
Get the node’s output ports.
Source§fn process(
&mut self,
input: Option<FilterFrame>,
) -> GraphResult<Option<FilterFrame>>
fn process( &mut self, input: Option<FilterFrame>, ) -> GraphResult<Option<FilterFrame>>
Process available input and produce output. Read more
Source§fn reset(&mut self) -> GraphResult<()>
fn reset(&mut self) -> GraphResult<()>
Reset the node to initial state.
Source§fn initialize(&mut self) -> GraphResult<()>
fn initialize(&mut self) -> GraphResult<()>
Initialize the node before processing starts.
Source§fn flush(&mut self) -> GraphResult<Vec<FilterFrame>>
fn flush(&mut self) -> GraphResult<Vec<FilterFrame>>
Flush any buffered data.
Source§fn output_port(&self, id: PortId) -> Option<&OutputPort>
fn output_port(&self, id: PortId) -> Option<&OutputPort>
Get output port by ID.
Source§fn accepts_input(&self, port_type: PortType) -> bool
fn accepts_input(&self, port_type: PortType) -> bool
Check if node accepts the given port type as input.
Source§fn produces_output(&self, port_type: PortType) -> bool
fn produces_output(&self, port_type: PortType) -> bool
Check if node produces the given port type as output.
Auto Trait Implementations§
impl !RefUnwindSafe for ConditionalRouter
impl !UnwindSafe for ConditionalRouter
impl Freeze for ConditionalRouter
impl Send for ConditionalRouter
impl Sync for ConditionalRouter
impl Unpin for ConditionalRouter
impl UnsafeUnpin for ConditionalRouter
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more