pub struct StreamSet<I, T> { /* private fields */ }Expand description
Stream set.
Stream sets are homogeneous collections of streams, implementing common set
operations like union, intersection, and difference. They are represented
as a vector of streams, in order to preserve the ordering in which they
were added, which is crucial for operators like Stream::coalesce.
Operators implemented with stream sets include:
Note that stream sets implement set operations themselves, including union, intersection, and difference, which means they can be combined with other stream sets to implement combinatorical structural operators. However, the union set operation is likely the most common use case.
Implementations§
Source§impl<I, T> StreamSet<I, T>
impl<I, T> StreamSet<I, T>
Sourcepub fn union<S>(self, streams: S) -> Selfwhere
S: IntoStreamSet<I, T>,
pub fn union<S>(self, streams: S) -> Selfwhere
S: IntoStreamSet<I, T>,
Creates the union of two stream sets.
§Examples
use zrx_stream::combinator::IntoStreamSet;
use zrx_stream::workspace::Workspace;
// Create workspace and workflow
let workspace = Workspace::<&str>::new();
let workflow = workspace.add_workflow();
// Create streams (homogeneous)
let a = workflow.add_source::<i32>();
let b = workflow.add_source::<i32>();
let c = workflow.add_source::<i32>();
// Create union of stream sets
let set = [&a, &b].into_stream_set().union([&b, &c]);
assert_eq!(set.len(), 3);Sourcepub fn intersection<S>(self, streams: S) -> Selfwhere
S: IntoStreamSet<I, T>,
pub fn intersection<S>(self, streams: S) -> Selfwhere
S: IntoStreamSet<I, T>,
Creates the intersection of two stream sets.
§Examples
use zrx_stream::combinator::IntoStreamSet;
use zrx_stream::workspace::Workspace;
// Create workspace and workflow
let workspace = Workspace::<&str>::new();
let workflow = workspace.add_workflow();
// Create streams (homogeneous)
let a = workflow.add_source::<i32>();
let b = workflow.add_source::<i32>();
let c = workflow.add_source::<i32>();
// Create intersection of stream sets
let set = [&a, &b].into_stream_set().intersection([&b, &c]);
assert_eq!(set.len(), 1);Sourcepub fn difference<S>(self, streams: S) -> Selfwhere
S: IntoStreamSet<I, T>,
pub fn difference<S>(self, streams: S) -> Selfwhere
S: IntoStreamSet<I, T>,
Creates the difference of two stream sets.
§Examples
use zrx_stream::combinator::IntoStreamSet;
use zrx_stream::workspace::Workspace;
// Create workspace and workflow
let workspace = Workspace::<&str>::new();
let workflow = workspace.add_workflow();
// Create streams (homogeneous)
let a = workflow.add_source::<i32>();
let b = workflow.add_source::<i32>();
let c = workflow.add_source::<i32>();
// Create difference of stream sets
let set = [&a, &b].into_stream_set().difference([&b, &c]);
assert_eq!(set.len(), 1);Sourcepub fn is_subset<S>(&self, streams: S) -> boolwhere
S: IntoStreamSet<I, T>,
pub fn is_subset<S>(&self, streams: S) -> boolwhere
S: IntoStreamSet<I, T>,
Returns whether the stream set is a subset.
§Examples
use zrx_stream::combinator::IntoStreamSet;
use zrx_stream::workspace::Workspace;
// Create workspace and workflow
let workspace = Workspace::<&str>::new();
let workflow = workspace.add_workflow();
// Create streams (homogeneous)
let a = workflow.add_source::<i32>();
let b = workflow.add_source::<i32>();
// Create stream set and check for subset
let set = a.into_stream_set();
assert!(set.is_subset([&a, &b]));Sourcepub fn is_superset<S>(&self, streams: S) -> boolwhere
S: IntoStreamSet<I, T>,
pub fn is_superset<S>(&self, streams: S) -> boolwhere
S: IntoStreamSet<I, T>,
Returns whether the stream set is a superset.
§Examples
use zrx_stream::combinator::IntoStreamSet;
use zrx_stream::workspace::Workspace;
// Create workspace and workflow
let workspace = Workspace::<&str>::new();
let workflow = workspace.add_workflow();
// Create streams (homogeneous)
let a = workflow.add_source::<i32>();
let b = workflow.add_source::<i32>();
// Create stream set and check for superset
let set = [&a, &b].into_stream_set();
assert!(set.is_superset(&a));Sourcepub fn get(&self, index: usize) -> Option<&Stream<I, T>>
pub fn get(&self, index: usize) -> Option<&Stream<I, T>>
Returns a reference to the stream at the given index.
§Examples
use zrx_stream::combinator::IntoStreamSet;
use zrx_stream::workspace::Workspace;
// Create workspace and workflow
let workspace = Workspace::<&str>::new();
let workflow = workspace.add_workflow();
// Create streams (homogeneous)
let a = workflow.add_source::<i32>();
let b = workflow.add_source::<i32>();
// Create stream set and obtain stream reference
let set = [&a, &b].into_stream_set();
assert_eq!(set.get(0), Some(&a));Sourcepub fn contains(&self, stream: &Stream<I, T>) -> bool
pub fn contains(&self, stream: &Stream<I, T>) -> bool
Returns whether the stream set contains the given stream.
§Examples
use zrx_stream::combinator::IntoStreamSet;
use zrx_stream::workspace::Workspace;
// Create workspace and workflow
let workspace = Workspace::<&str>::new();
let workflow = workspace.add_workflow();
// Create streams (homogeneous)
let a = workflow.add_source::<i32>();
let b = workflow.add_source::<i32>();
// Create stream set and ensure presence of stream
let set = [&a, &b].into_stream_set();
assert!(set.contains(&a));Trait Implementations§
Source§impl<I, T> FromIterator<Stream<I, T>> for StreamSet<I, T>
impl<I, T> FromIterator<Stream<I, T>> for StreamSet<I, T>
Source§fn from_iter<S>(iter: S) -> Selfwhere
S: IntoIterator<Item = Stream<I, T>>,
fn from_iter<S>(iter: S) -> Selfwhere
S: IntoIterator<Item = Stream<I, T>>,
Creates a stream set from an iterator.
§Examples
use zrx_stream::combinator::{IntoStreamSet, StreamSet};
use zrx_stream::workspace::Workspace;
// Create workspace and workflow
let workspace = Workspace::<&str>::new();
let workflow = workspace.add_workflow();
// Create streams (homogeneous)
let a = workflow.add_source::<i32>();
let b = workflow.add_source::<i32>();
// Create stream set from iterator
let set = StreamSet::from_iter([a, b]);Source§impl<I, T> IntoIterator for StreamSet<I, T>
impl<I, T> IntoIterator for StreamSet<I, T>
Source§fn into_iter(self) -> Self::IntoIter
fn into_iter(self) -> Self::IntoIter
Creates an iterator over the stream set.
§Examples
use zrx_stream::combinator::{IntoStreamSet, StreamSet};
use zrx_stream::workspace::Workspace;
// Create workspace and workflow
let workspace = Workspace::<&str>::new();
let workflow = workspace.add_workflow();
// Create streams (homogeneous)
let a = workflow.add_source::<i32>();
let b = workflow.add_source::<i32>();
// Create and iterate over stream set
let set = StreamSet::from_iter([a, b]);
for stream in set {
println!("{stream:?}");
}Auto Trait Implementations§
impl<I, T> Freeze for StreamSet<I, T>
impl<I, T> !RefUnwindSafe for StreamSet<I, T>
impl<I, T> !Send for StreamSet<I, T>
impl<I, T> !Sync for StreamSet<I, T>
impl<I, T> Unpin for StreamSet<I, T>where
T: Unpin,
impl<I, T> UnsafeUnpin for StreamSet<I, T>
impl<I, T> !UnwindSafe for StreamSet<I, T>
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§impl<T, E> IntoReport<T, E> for Twhere
E: Error,
impl<T, E> IntoReport<T, E> for Twhere
E: Error,
Source§fn into_report(self) -> Result<Report<T>, E>
fn into_report(self) -> Result<Report<T>, E>
Creates a report from a value T and wraps it in a result.
§Examples
use std::io::Error;
use zrx_diagnostic::report::IntoReport;
// Define function returning a value
fn f() -> impl IntoReport<i32, Error> {
42
}
// Invoke function and create report
let res = f().into_report();