pub trait SinkSocket: IntoInnerSocket {
// Provided methods
fn send(
self,
multipart: Multipart,
) -> <<Self as IntoInnerSocket>::Socket as InnerSocket<Self>>::Request { ... }
fn sink(
self,
buffer_size: usize,
) -> <<Self as IntoInnerSocket>::Socket as InnerSocket<Self>>::Sink { ... }
}Expand description
This trait provides the basic Sink support for ZeroMQ Sockets. It depends on IntoInnerSocket and
provides the send and sink methods.
Provided Methods§
Sourcefn send(
self,
multipart: Multipart,
) -> <<Self as IntoInnerSocket>::Socket as InnerSocket<Self>>::Request
fn send( self, multipart: Multipart, ) -> <<Self as IntoInnerSocket>::Socket as InnerSocket<Self>>::Request
Send a single multipart message to the socket.
§Example, using a Pub wrapper type
extern crate zmq;
extern crate futures;
extern crate tokio;
extern crate tokio_zmq;
use std::sync::Arc;
use futures::Future;
use tokio_zmq::{prelude::*, async_types::MultipartStream, Error, Pub};
fn main() {
let context = Arc::new(zmq::Context::new());
let msg = zmq::Message::from_slice(b"Hello");
let fut = Pub::builder(context)
.connect("tcp://localhost:5569")
.build()
.and_then(|zpub| zpub.send(msg.into()));
// tokio::run(fut.map(|_| ()).or_else(|e| {
// println!("Error: {}", e);
// Ok(())
// }));
}Sourcefn sink(
self,
buffer_size: usize,
) -> <<Self as IntoInnerSocket>::Socket as InnerSocket<Self>>::Sink
fn sink( self, buffer_size: usize, ) -> <<Self as IntoInnerSocket>::Socket as InnerSocket<Self>>::Sink
Send a stream of multipart messages to the socket.
It takes a buffer_size argument, which will determine how many Multiparts can be
submitted into the send queue before the sink applies backpressure.
§Example, using a Pub wrapper type
extern crate zmq;
extern crate futures;
extern crate tokio;
extern crate tokio_zmq;
use std::sync::Arc;
use futures::{Future, Stream, stream::iter_ok};
use tokio_zmq::{prelude::*, async_types::MultipartStream, Error, Multipart, Pub};
fn main() {
let context = Arc::new(zmq::Context::new());
let fut = Pub::builder(context)
.connect("tcp://localhost:5570")
.build()
.and_then(|zpub| {
iter_ok(0..5)
.map(|i| {
zmq::Message::from_slice(format!("i: {}", i).as_bytes()).into()
})
.forward(zpub.sink(25))
});
// tokio::run(fut.map(|_| ()).or_else(|e| {
// println!("Error: {}", e);
// Ok(())
// }));
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.