mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-03-21 21:20:45 +00:00
34 lines
800 B
Rust
34 lines
800 B
Rust
|
//! # WebSocket routes
|
||
|
//!
|
||
|
//! @author Pierre Hubert
|
||
|
|
||
|
use crate::data::error::Res;
|
||
|
use crate::data::user_ws_request_handler::WsRequestHandler;
|
||
|
|
||
|
pub type WsRequestProcess = Box<dyn Fn(&mut WsRequestHandler) -> Res>;
|
||
|
|
||
|
/// WebSocket route
|
||
|
pub struct WsRoute {
|
||
|
pub route: String,
|
||
|
pub handler: WsRequestProcess,
|
||
|
}
|
||
|
|
||
|
impl WsRoute {
|
||
|
pub fn new<H>(route: &str, handler: H) -> WsRoute
|
||
|
where H: 'static + Fn(&mut WsRequestHandler) -> Res {
|
||
|
WsRoute {
|
||
|
route: route.to_string(),
|
||
|
handler: Box::new(handler),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// Get the list of available WebSocket routes
|
||
|
pub fn get_ws_routes() -> Vec<WsRoute> {
|
||
|
vec![]
|
||
|
}
|
||
|
|
||
|
/// Search for a route
|
||
|
pub fn find_ws_route(uri: &str) -> Option<WsRoute> {
|
||
|
get_ws_routes().into_iter().find(|r| r.route == uri)
|
||
|
}
|