pub trait Sink<K, V, T, S>: Sealed {
// Required method
fn sink(self, name: &str, sink: S);
}Expand description
Output messages from a Malstrom stream somewhere
Required Methods§
Sourcefn sink(self, name: &str, sink: S)
fn sink(self, name: &str, sink: S)
Sink all messages in this stream to the given output. This will consume the messages. If you whish to write to multiple outputs, consider calling .cloned() on the stream.
§Example
use malstrom::operators::*;
use malstrom::runtime::SingleThreadRuntime;
use malstrom::snapshot::NoPersistence;
use malstrom::sources::{SingleIteratorSource, StatelessSource};
use malstrom::worker::StreamProvider;
use malstrom::sinks::{VecSink, StatelessSink};
let sink = VecSink::new();
let sink_clone = sink.clone();
SingleThreadRuntime::builder()
.persistence(NoPersistence)
.build(move |provider: &mut dyn StreamProvider| {
provider.new_stream()
.source("numbers", StatelessSource::new(SingleIteratorSource::new(0..10)))
.sink("sink", StatelessSink::new(sink_clone));
})
.execute()
.unwrap();
let expected: Vec<i32> = (0..10).collect();
let out: Vec<i32> = sink.into_iter().map(|x| x.value).collect();
assert_eq!(out, expected);Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".