pub trait WebSocketServerTrait: DowncastSync {
    // Required methods
    fn listen<'life0, 'async_trait>(
        self: Arc<Self>,
        addr: &'life0 str
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stop(&self) -> Result<()>;
    fn join<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stop_and_join<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Base WebSocketServer trait allows the WebSocketServer<T> struct to be retained by the trait reference by castring it to the trait as follows:

use std::sync::Arc;
use async_trait::async_trait;
use workflow_websocket::server::{Result,WebSocketServerTrait};

struct Server{}

#[async_trait]
impl WebSocketServerTrait for Server{
    async fn listen(self: Arc<Self>, addr: &str) -> Result<()>{
        Ok(())
    }
    fn stop(&self) -> Result<()>{
        Ok(())
    }
    async fn join(&self) -> Result<()>{
        Ok(())
    }
    async fn stop_and_join(&self) -> Result<()>{
        Ok(())
    }
}
let server_trait: Arc<dyn WebSocketServerTrait> = Arc::new(Server{});
let server = server_trait.downcast_arc::<Server>();

This can help simplify web socket handling in case the supplied T generic contains complex generic types that typically results in generics propagating up into the ownership type chain.

This trait is used in the workflow-rpc crate to isolate RpcHandler generics from the RpcServer owning the WebSocket.

Required Methods§

source

fn listen<'life0, 'async_trait>( self: Arc<Self>, addr: &'life0 str ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

source

fn stop(&self) -> Result<()>

source

fn join<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

source

fn stop_and_join<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Implementations§

source§

impl dyn WebSocketServerTrait

source

pub fn is<__T: WebSocketServerTrait>(&self) -> bool

Returns true if the trait object wraps an object of type __T.

source

pub fn downcast<__T: WebSocketServerTrait>( self: Box<Self> ) -> Result<Box<__T>, Box<Self>>

Returns a boxed object from a boxed trait object if the underlying object is of type __T. Returns the original boxed trait if it isn’t.

source

pub fn downcast_rc<__T: WebSocketServerTrait>( self: Rc<Self> ) -> Result<Rc<__T>, Rc<Self>>

Returns an Rc-ed object from an Rc-ed trait object if the underlying object is of type __T. Returns the original Rc-ed trait if it isn’t.

source

pub fn downcast_ref<__T: WebSocketServerTrait>(&self) -> Option<&__T>

Returns a reference to the object within the trait object if it is of type __T, or None if it isn’t.

source

pub fn downcast_mut<__T: WebSocketServerTrait>(&mut self) -> Option<&mut __T>

Returns a mutable reference to the object within the trait object if it is of type __T, or None if it isn’t.

source

pub fn downcast_arc<__T>(self: Arc<Self>) -> Result<Arc<__T>, Arc<Self>>where __T: Any + Send + Sync + WebSocketServerTrait,

Returns an Arc-ed object from an Arc-ed trait object if the underlying object is of type __T. Returns the original Arc-ed trait if it isn’t.

Implementors§