Struct fizyr_rpc::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> !RefUnwindSafe for Peer<Transport>

§

impl<Transport> Send for Peer<Transport>

§

impl<Transport> Sync for Peer<Transport>
where Transport: Sync,

§

impl<Transport> Unpin for Peer<Transport>
where Transport: Unpin,

§

impl<Transport> !UnwindSafe for Peer<Transport>

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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.