Skip to main content

Peer

Struct Peer 

Source
pub struct Peer<Transport: Transport> { /* private fields */ }
Expand description

Peer read/write loop.

This struct is used to run the read/write loop of the peer. To send or receive requests and stream messages, you need to use the PeerHandle instead.

Implementations§

Source§

impl<Transport: Transport> Peer<Transport>

Source

pub fn new(transport: Transport) -> (Self, PeerHandle<Transport::Body>)

Create a new peer and a handle to it.

The Peer itself is used to run the read/write loop. The returned PeerHandle is used to send and receive requests and stream messages.

If Self::run() is not called (or aborted), none of the functions of the PeerHandle will work. They will just wait forever.

You can also use Self::spawn() to run the read/write loop in a newly spawned task, and only get a PeerHandle. You should only use Self::spawn() if you do not need full control over the execution of the read/write loop.

Source

pub fn spawn(transport: Transport) -> PeerHandle<Transport::Body>

Spawn a peer in a new task, and get a handle to the peer.

The spawned task will immediately be detached. It can not be joined.

The returned PeerHandle can be used to send and receive requests and stream messages.

If you need more control of the execution of the peer read/write loop, you should use Self::new() instead.

Source

pub async fn connect<'a, Address>( address: Address, config: Transport::Config, ) -> Result<(PeerHandle<Transport::Body>, Transport::Info)>
where Address: 'a, Transport: Connect<'a, Address>,

Connect to a remote server.

Similar to Self::spawn(), this spawns a background task for the peer.

The returned PeerHandle can be used to send and receive requests and stream messages.

The type of address accepted depends on the transport. For internet transports such as TCP, the address must implement tokio::net::ToSocketAddrs. For unix transports, the address must implement AsRef<std::path::Path>.

Source

pub async fn run(self)

Run the read/write loop.

Source

pub fn transport(&self) -> &Transport

Get direct access to the underlying transport.

Source

pub fn transport_mut(&mut self) -> &mut Transport

Get direct mutable access to the underlying transport.

Auto Trait Implementations§

§

impl<Transport> Freeze for Peer<Transport>
where Transport: Freeze, RequestTracker<<Transport as Transport>::Body>: Freeze, UnboundedSender<Command<<Transport as Transport>::Body>>: Freeze, UnboundedReceiver<Command<<Transport as Transport>::Body>>: Freeze, UnboundedSender<Result<ReceivedMessage<<Transport as Transport>::Body>, Error>>: Freeze,

§

impl<Transport> RefUnwindSafe for Peer<Transport>
where Transport: RefUnwindSafe, RequestTracker<<Transport as Transport>::Body>: RefUnwindSafe, UnboundedSender<Command<<Transport as Transport>::Body>>: RefUnwindSafe, UnboundedReceiver<Command<<Transport as Transport>::Body>>: RefUnwindSafe, UnboundedSender<Result<ReceivedMessage<<Transport as Transport>::Body>, Error>>: RefUnwindSafe,

§

impl<Transport> Send for Peer<Transport>
where RequestTracker<<Transport as Transport>::Body>: Send, UnboundedSender<Command<<Transport as Transport>::Body>>: Send, UnboundedReceiver<Command<<Transport as Transport>::Body>>: Send, UnboundedSender<Result<ReceivedMessage<<Transport as Transport>::Body>, Error>>: Send,

§

impl<Transport> Sync for Peer<Transport>
where Transport: Sync, RequestTracker<<Transport as Transport>::Body>: Sync, UnboundedSender<Command<<Transport as Transport>::Body>>: Sync, UnboundedReceiver<Command<<Transport as Transport>::Body>>: Sync, UnboundedSender<Result<ReceivedMessage<<Transport as Transport>::Body>, Error>>: Sync,

§

impl<Transport> Unpin for Peer<Transport>
where Transport: Unpin, RequestTracker<<Transport as Transport>::Body>: Unpin, UnboundedSender<Command<<Transport as Transport>::Body>>: Unpin, UnboundedReceiver<Command<<Transport as Transport>::Body>>: Unpin, UnboundedSender<Result<ReceivedMessage<<Transport as Transport>::Body>, Error>>: Unpin,

§

impl<Transport> UnsafeUnpin for Peer<Transport>
where Transport: UnsafeUnpin, RequestTracker<<Transport as Transport>::Body>: UnsafeUnpin, UnboundedSender<Command<<Transport as Transport>::Body>>: UnsafeUnpin, UnboundedReceiver<Command<<Transport as Transport>::Body>>: UnsafeUnpin, UnboundedSender<Result<ReceivedMessage<<Transport as Transport>::Body>, Error>>: UnsafeUnpin,

§

impl<Transport> UnwindSafe for Peer<Transport>
where Transport: UnwindSafe, RequestTracker<<Transport as Transport>::Body>: UnwindSafe, UnboundedSender<Command<<Transport as Transport>::Body>>: UnwindSafe, UnboundedReceiver<Command<<Transport as Transport>::Body>>: UnwindSafe, UnboundedSender<Result<ReceivedMessage<<Transport as Transport>::Body>, Error>>: UnwindSafe,

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.