OwnedReader

Struct OwnedReader 

Source
pub struct OwnedReader { /* private fields */ }

Implementations§

Source§

impl OwnedReader

Source

pub fn remote(&self) -> RemoteAddr

Returns the address of the other end of this connection.

Source

pub fn is_closed(&self) -> bool

Returns true if this connection is closed.

Source

pub async fn recv<T>(&mut self) -> Option<T>

Receive data from the connection.

Examples found in repository?
examples/broadcast.rs (line 120)
118async fn handle_client_connection(state: NodeStateRef, conn: api::Connection) {
119    let (mut reader, _writer) = conn.split();
120    let msg = reader.recv::<Message>().await.unwrap();
121    if let Message::Payload(id, payload) = msg {
122        state.borrow_mut().handle_message_from_client(id, payload);
123    } else {
124        panic!("unexpected.");
125    }
126}
127
128/// Handle the connection that is made from another node.
129async fn handle_connection(state: NodeStateRef, conn: api::Connection) {
130    let remote = conn.remote();
131    let (mut reader, writer) = conn.split();
132
133    // Insert the writer half of this connection into the state.
134    let b_conn: BroadcastConnection = writer.into();
135    state.borrow_mut().conns.insert(remote, b_conn);
136
137    while let Some(msg) = reader.recv::<Message>().await {
138        match msg {
139            Message::Payload(id, payload) => {
140                state.borrow_mut().handle_message(remote, id, payload);
141            },
142            Message::Advr(id) => {
143                state.borrow_mut().handle_advr(remote, id);
144            },
145            Message::Want(id) => {
146                state.borrow_mut().handle_want(remote, id);
147            },
148        }
149    }
150}

Auto Trait Implementations§

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

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V