Trait workflow_rpc::server::WebSocketServerTrait
source · pub trait WebSocketServerTrait: DowncastSync {
// Required methods
fn listen<'life0, 'async_trait>(
self: Arc<Self>,
addr: &'life0 str,
config: Option<WebSocketConfig>
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn stop(&self) -> Result<(), Error>;
fn join<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn stop_and_join<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
}
Expand description
Base WebSocketServer trait allows the WebSocketServer<T>
struct
to be retained by the trait reference by casting 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§
fn listen<'life0, 'async_trait>(
self: Arc<Self>,
addr: &'life0 str,
config: Option<WebSocketConfig>
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn stop(&self) -> Result<(), Error>
fn join<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn stop_and_join<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Implementations§
source§impl dyn WebSocketServerTrait
impl dyn WebSocketServerTrait
sourcepub fn is<__T>(&self) -> boolwhere
__T: WebSocketServerTrait,
pub fn is<__T>(&self) -> boolwhere
__T: WebSocketServerTrait,
Returns true if the trait object wraps an object of type __T
.
sourcepub fn downcast<__T>(
self: Box<dyn WebSocketServerTrait>
) -> Result<Box<__T>, Box<dyn WebSocketServerTrait>>where
__T: WebSocketServerTrait,
pub fn downcast<__T>(
self: Box<dyn WebSocketServerTrait>
) -> Result<Box<__T>, Box<dyn WebSocketServerTrait>>where
__T: WebSocketServerTrait,
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.
sourcepub fn downcast_rc<__T>(
self: Rc<dyn WebSocketServerTrait>
) -> Result<Rc<__T>, Rc<dyn WebSocketServerTrait>>where
__T: WebSocketServerTrait,
pub fn downcast_rc<__T>(
self: Rc<dyn WebSocketServerTrait>
) -> Result<Rc<__T>, Rc<dyn WebSocketServerTrait>>where
__T: WebSocketServerTrait,
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.
sourcepub fn downcast_ref<__T>(&self) -> Option<&__T>where
__T: WebSocketServerTrait,
pub fn downcast_ref<__T>(&self) -> Option<&__T>where
__T: WebSocketServerTrait,
Returns a reference to the object within the trait object if it is of type __T
, or
None
if it isn’t.
sourcepub fn downcast_mut<__T>(&mut self) -> Option<&mut __T>where
__T: WebSocketServerTrait,
pub fn downcast_mut<__T>(&mut self) -> Option<&mut __T>where
__T: WebSocketServerTrait,
Returns a mutable reference to the object within the trait object if it is of type
__T
, or None
if it isn’t.
sourcepub fn downcast_arc<__T>(
self: Arc<dyn WebSocketServerTrait>
) -> Result<Arc<__T>, Arc<dyn WebSocketServerTrait>>
pub fn downcast_arc<__T>( self: Arc<dyn WebSocketServerTrait> ) -> Result<Arc<__T>, Arc<dyn 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.