[][src]Struct meows::Server

pub struct Server<ServerState, ClientState> { /* fields omitted */ }

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]

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]

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]

pub fn new() -> Self[src]

Auto Trait Implementations

impl<ServerState, ClientState> !RefUnwindSafe for Server<ServerState, ClientState>

impl<ServerState, ClientState> Send for Server<ServerState, ClientState> where
    ServerState: Send + Sync

impl<ServerState, ClientState> Sync for Server<ServerState, ClientState> where
    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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,