Struct Connection

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

Source

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