Skip to main content

SessionServer

Struct SessionServer 

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

Implementations§

Source§

impl SessionServer

Source

pub async fn bind(addr: &str) -> Result<Self>

Examples found in repository?
examples/server.rs (line 16)
15async fn main() -> session_rs::Result<()> {
16    let server = SessionServer::bind("127.0.0.1:8080").await?;
17
18    server
19        .session_loop(async |session, _| {
20            session
21                .on::<Data, _>(async |_, req| {
22                    println!("Msg from client: {req}");
23
24                    if req == "invalid_data" {
25                        return Err("Invalid data".to_string());
26                    }
27
28                    Ok("Hello from server".to_string())
29                })
30                .await;
31
32            Ok(())
33        })
34        .await
35}
Source

pub async fn accept(&self) -> Result<(Session, SocketAddr)>

Source

pub async fn session_loop<Fut: Future<Output = Result<()>> + Send + 'static>( &self, on_conn: impl Fn(Session, SocketAddr) -> Fut + 'static, ) -> Result<()>

Examples found in repository?
examples/server.rs (lines 19-33)
15async fn main() -> session_rs::Result<()> {
16    let server = SessionServer::bind("127.0.0.1:8080").await?;
17
18    server
19        .session_loop(async |session, _| {
20            session
21                .on::<Data, _>(async |_, req| {
22                    println!("Msg from client: {req}");
23
24                    if req == "invalid_data" {
25                        return Err("Invalid data".to_string());
26                    }
27
28                    Ok("Hello from server".to_string())
29                })
30                .await;
31
32            Ok(())
33        })
34        .await
35}

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> Same for T

Source§

type Output = T

Should always be Self
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.