Skip to main content

StreamSet

Struct StreamSet 

Source
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>

Source

pub fn union<S>(self, streams: S) -> Self
where 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);
Source

pub fn intersection<S>(self, streams: S) -> Self
where 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);
Source

pub fn difference<S>(self, streams: S) -> Self
where 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);
Source

pub fn is_subset<S>(&self, streams: S) -> bool
where 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]));
Source

pub fn is_superset<S>(&self, streams: S) -> bool
where 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));
Source

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));
Source

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));
Source§

impl<I, T> StreamSet<I, T>

Source

pub fn len(&self) -> usize

Returns the number of streams.

Source

pub fn is_empty(&self) -> bool

Returns whether there are any streams.

Source§

impl<I, T> StreamSet<I, T>
where I: Id, T: Value + Clone,

Source

pub fn into_coalesce(self) -> Option<Stream<I, T>>

Source§

impl<I, T> StreamSet<I, T>
where I: Id, T: Value + Clone + Eq,

Source

pub fn into_difference(self) -> Option<Stream<I, T>>

Source§

impl<I, T> StreamSet<I, T>
where I: Id, T: Value + Clone + Eq,

Source

pub fn into_intersection(self) -> Option<Stream<I, T>>

Source§

impl<I, T> StreamSet<I, T>
where I: Id, T: Value + Clone + Eq,

Source

pub fn into_union(self) -> Option<Stream<I, T>>

Trait Implementations§

Source§

impl<I: Clone, T: Clone> Clone for StreamSet<I, T>

Source§

fn clone(&self) -> StreamSet<I, T>

Returns a duplicate 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<I: Debug, T: Debug> Debug for StreamSet<I, T>

Source§

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

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

impl<I, T> FromIterator<Stream<I, T>> for StreamSet<I, T>

Source§

fn from_iter<S>(iter: S) -> Self
where 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>

Source§

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:?}");
}
Source§

type Item = Stream<I, T>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<StreamSet<I, T> as IntoIterator>::Item>

Which kind of iterator are we turning this into?

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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, E> IntoReport<T, E> for T
where E: Error,

Source§

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();
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<T> Value for T
where T: Debug + 'static,