Struct distant_core::Transport
source · [−]pub struct Transport<T, U>(_)
where
T: DataStream,
U: Codec;
Expand description
Represents a transport of data across the network
Implementations
sourceimpl Transport<InmemoryStream, PlainCodec>
impl Transport<InmemoryStream, PlainCodec>
sourcepub fn pair(
buffer: usize
) -> (Transport<InmemoryStream, PlainCodec>, Transport<InmemoryStream, PlainCodec>)
pub fn pair(
buffer: usize
) -> (Transport<InmemoryStream, PlainCodec>, Transport<InmemoryStream, PlainCodec>)
Produces a pair of inmemory transports that are connected to each other using a standard codec
Sets the buffer for message passing for each underlying stream to the given buffer size
sourceimpl<U: Codec> Transport<TcpStream, U>
impl<U: Codec> Transport<TcpStream, U>
sourcepub async fn connect(addrs: impl ToSocketAddrs, codec: U) -> Result<Self>
pub async fn connect(addrs: impl ToSocketAddrs, codec: U) -> Result<Self>
Establishes a connection to one of the specified addresses and uses the provided codec for transportation
sourcepub fn peer_addr(&self) -> Result<SocketAddr>
pub fn peer_addr(&self) -> Result<SocketAddr>
Returns the address of the peer the transport is connected to
sourceimpl<U: Codec> Transport<UnixStream, U>
impl<U: Codec> Transport<UnixStream, U>
sourceimpl<T, U> Transport<T, U> where
T: DataStream,
U: Codec,
impl<T, U> Transport<T, U> where
T: DataStream,
U: Codec,
sourcepub fn new(stream: T, codec: U) -> Self
pub fn new(stream: T, codec: U) -> Self
Creates a new instance of the transport, wrapping the stream in a Framed<T, XChaCha20Poly1305Codec>
sourcepub async fn send<D: Serialize>(
&mut self,
data: D
) -> Result<(), TransportError>
pub async fn send<D: Serialize>(
&mut self,
data: D
) -> Result<(), TransportError>
Sends some data across the wire, waiting for it to completely send
sourcepub async fn receive<R: DeserializeOwned>(
&mut self
) -> Result<Option<R>, TransportError>
pub async fn receive<R: DeserializeOwned>(
&mut self
) -> Result<Option<R>, TransportError>
Receives some data from out on the wire, waiting until it’s available, returning none if the transport is now closed
sourcepub fn to_connection_tag(&self) -> String
pub fn to_connection_tag(&self) -> String
Returns a textual description of the transport’s underlying connection
sourcepub fn get_ref(&self) -> &T
pub fn get_ref(&self) -> &T
Returns a reference to the underlying I/O stream
Note that care should be taken to not tamper with the underlying stream of data coming in as it may corrupt the stream of frames otherwise being worked with
sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Returns a reference to the underlying I/O stream
Note that care should be taken to not tamper with the underlying stream of data coming in as it may corrupt the stream of frames otherwise being worked with
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the transport, returning its underlying I/O stream
Note that care should be taken to not tamper with the underlying stream of data coming in as it may corrupt the stream of frames otherwise being worked with.
sourcepub fn into_split(
self
) -> (TransportReadHalf<T::Read, U>, TransportWriteHalf<T::Write, U>)
pub fn into_split(
self
) -> (TransportReadHalf<T::Read, U>, TransportWriteHalf<T::Write, U>)
Splits transport into read and write halves
Trait Implementations
Auto Trait Implementations
impl<T, U> RefUnwindSafe for Transport<T, U> where
T: RefUnwindSafe,
U: RefUnwindSafe,
impl<T, U> Send for Transport<T, U> where
T: Send,
U: Send,
impl<T, U> Sync for Transport<T, U> where
T: Sync,
U: Sync,
impl<T, U> Unpin for Transport<T, U>
impl<T, U> UnwindSafe for Transport<T, U> where
T: UnwindSafe,
U: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more