pub struct SessionServer { /* private fields */ }Implementations§
Source§impl SessionServer
impl SessionServer
Sourcepub async fn bind(addr: &str) -> Result<Self>
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}pub async fn accept(&self) -> Result<(Session, SocketAddr)>
Sourcepub async fn session_loop<Fut: Future<Output = Result<()>> + Send + 'static>(
&self,
on_conn: impl Fn(Session, SocketAddr) -> Fut + 'static,
) -> Result<()>
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§
impl !Freeze for SessionServer
impl RefUnwindSafe for SessionServer
impl Send for SessionServer
impl Sync for SessionServer
impl Unpin for SessionServer
impl UnsafeUnpin for SessionServer
impl UnwindSafe for SessionServer
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