pub struct Port { /* private fields */ }
Expand description
One half of a bidirectional communication channel.
This is a lower-level construct for sending and receiving binary messages.
Most code should use a higher-level channel returned by
mesh_channel::channel()
, which uses this type internally.
Implementations§
Source§impl Port
impl Port
Sourcepub fn new_pair() -> (Self, Self)
pub fn new_pair() -> (Self, Self)
Creates a new bidirectional channel, returning a pair of ports.
Sourcepub fn set_handler<T: HandlePortEvent>(self, handler: T) -> PortWithHandler<T>
pub fn set_handler<T: HandlePortEvent>(self, handler: T) -> PortWithHandler<T>
Sets the handler for incoming messages.
If there are any queued incoming messages, or if the port has already been closed or failed, then the relevant handler methods will be called directly on this thread.
Sourcepub fn bridge(self, other: Self)
pub fn bridge(self, other: Self)
Bridges two channels together so that the peer of self
is connected
directly to the peer of other
.
Sourcepub fn send_protobuf<T: DefaultEncoding>(&self, value: T)
pub fn send_protobuf<T: DefaultEncoding>(&self, value: T)
Send a protobuf-encodable message to the peer.
Prefer Port::send
if you already have a Message
,
OwnedMessage
, or serialized message, or if the recipient is known to
take advantage of the OwnedMessage::try_unwrap
optimization.
Otherwise, this method is more efficient since it can avoid an extra
allocation to construct a Message
.