Struct fizyr_rpc::Peer[][src]

pub struct Peer<Transport: Transport> { /* fields omitted */ }
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

impl<Transport: Transport> Peer<Transport>[src]

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

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), then 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.

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

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.

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

Connect to a remote peer.

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

pub async fn run(self)[src]

Run the read/write loop.

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.