pub struct Connection<Resume: Session> { /* private fields */ }
Expand description
A client’s handle to an active suspended connection. Use resume
to enter the
server’s event loop and continue interaction.
Must not be dropped. Specify the resumption protocol to handle disconnecting.
Implementations§
Source§impl<Resume: Session> Connection<Resume>
impl<Resume: Session> Connection<Resume>
Sourcepub fn resume(self) -> Resume
pub fn resume(self) -> Resume
Resumes the connection, entering the server’s event loop. Returns the client’s side of the connection resumption protocol.
Examples found in repository?
examples/chat.rs (line 166)
145fn handle_user(socket: WebSocketStream<TcpStream>) -> Recv<Option<Login>> {
146 let (write, read) = socket.split();
147 let inbox = handle_inbox(write);
148 let messages = read_socket(read);
149
150 fork(|try_login: Send<Option<Login>>| async {
151 let inbox = inbox.push(ChatLine::Info(format!("What's your name?")));
152 let Queue::Item(name, messages) = messages.pop().await else {
153 inbox.close1();
154 return try_login.send1(None);
155 };
156
157 let Ok(accepted) = try_login.choose(Some).send(Nick(name)).recv1().await else {
158 inbox
159 .push(ChatLine::Error(format!("Login refused")))
160 .close1();
161 return messages.for_each1(|_| future::ready(())).await;
162 };
163
164 let conn = messages
165 .fold1(accepted.send(inbox).recv1().await, |conn, content| async {
166 conn.resume()
167 .choose(Command::Message)
168 .send(content)
169 .recv1()
170 .await
171 })
172 .await;
173
174 conn.resume().send1(Command::Logout);
175 })
176}
Auto Trait Implementations§
impl<Resume> Freeze for Connection<Resume>
impl<Resume> !RefUnwindSafe for Connection<Resume>
impl<Resume> Send for Connection<Resume>
impl<Resume> !Sync for Connection<Resume>
impl<Resume> Unpin for Connection<Resume>
impl<Resume> !UnwindSafe for Connection<Resume>
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