[−][src]Struct meows::Server
The Server is the primary means of listening for messages
Implementations
impl<ServerState: 'static + Send + Sync, ClientState: 'static + Default + Send + Sync> Server<ServerState, ClientState>
[src]
pub fn with_state(state: ServerState) -> Self
[src]
with_state will construct the Server with the given state object
pub fn on(
&mut self,
message_type: &str,
invoke: impl Endpoint<ServerState, ClientState>
)
[src]
&mut self,
message_type: &str,
invoke: impl Endpoint<ServerState, ClientState>
)
Add a handler for a specific message type
use meows::*; #[macro_use] extern crate serde_derive; #[derive(Debug, Deserialize, Serialize)] struct Ping { msg: String, } async fn handle_ping(mut req: Request<(), ()>) -> Option<Message> { if let Some(ping) = req.from_value::<Ping>() { println!("Ping received: {:?}", ping); } Some(Message::text("pong")) } let mut server = Server::new(); server.on("ping", handle_ping);
pub fn default(
&mut self,
invoke: impl DefaultEndpoint<ServerState, ClientState>
)
[src]
&mut self,
invoke: impl DefaultEndpoint<ServerState, ClientState>
)
Set the default message handler, which will be invoked any time that a message is received that cannot be deserialized as a Meows Envelope
use meows::*; use std::sync::Arc; async fn my_default(message: String, _state: Arc<()>) -> Option<Message> { None } let mut server = Server::new(); server.default(my_default);
pub async fn serve<'_>(&'_ self, listen_on: String) -> Result<(), Error>
[src]
The serve() function will listen for inbound webhook connections
use meows::*; use smol; fn main() -> Result<(), std::io::Error> { let mut server = Server::new(); smol::run(async move { server.serve("127.0.0.1:8105".to_string()).await }) }
impl Server<(), ()>
[src]
Auto Trait Implementations
impl<ServerState, ClientState> !RefUnwindSafe for Server<ServerState, ClientState>
impl<ServerState, ClientState> Send for Server<ServerState, ClientState> where
ServerState: Send + Sync,
ServerState: Send + Sync,
impl<ServerState, ClientState> Sync for Server<ServerState, ClientState> where
ServerState: Send + Sync,
ServerState: Send + Sync,
impl<ServerState, ClientState> Unpin for Server<ServerState, ClientState>
impl<ServerState, ClientState> !UnwindSafe for Server<ServerState, ClientState>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,