pub struct OwnedReader { /* private fields */ }Implementations§
Source§impl OwnedReader
impl OwnedReader
Sourcepub fn remote(&self) -> RemoteAddr
pub fn remote(&self) -> RemoteAddr
Returns the address of the other end of this connection.
Sourcepub async fn recv<T>(&mut self) -> Option<T>where
T: DeserializeOwned,
pub async fn recv<T>(&mut self) -> Option<T>where
T: DeserializeOwned,
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§
impl Freeze for OwnedReader
impl RefUnwindSafe for OwnedReader
impl !Send for OwnedReader
impl !Sync for OwnedReader
impl Unpin for OwnedReader
impl UnwindSafe for OwnedReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more