Struct ServerBuilder

Source
pub struct ServerBuilder<M: Metadata, S: Middleware<M>> { /* private fields */ }
Expand description

Builder for WebSockets server

Implementations§

Source§

impl<M: Metadata + Default, S: Middleware<M>> ServerBuilder<M, S>
where S::Future: Unpin, S::CallFuture: Unpin,

Source

pub fn new<T>(handler: T) -> Self
where T: Into<MetaIoHandler<M, S>>,

Creates new ServerBuilder

Examples found in repository?
examples/ws.rs (line 11)
4fn main() {
5	let mut io = IoHandler::default();
6	io.add_sync_method("say_hello", |_params| {
7		println!("Processing");
8		Ok(Value::String("hello".to_owned()))
9	});
10
11	let server = ServerBuilder::new(io)
12		.start(&"0.0.0.0:3030".parse().unwrap())
13		.expect("Server must start with no issues");
14
15	server.wait().unwrap()
16}
Source§

impl<M: Metadata, S: Middleware<M>> ServerBuilder<M, S>
where S::Future: Unpin, S::CallFuture: Unpin,

Source

pub fn with_meta_extractor<T, E>(handler: T, extractor: E) -> Self
where T: Into<MetaIoHandler<M, S>>, E: MetaExtractor<M>,

Creates new ServerBuilder

Source

pub fn event_loop_executor(self, executor: TaskExecutor) -> Self

Utilize existing event loop executor to poll RPC results.

Source

pub fn session_meta_extractor<T: MetaExtractor<M>>(self, extractor: T) -> Self

Sets a meta extractor.

Source

pub fn allowed_origins(self, allowed_origins: DomainsValidation<Origin>) -> Self

Allowed origins.

Source

pub fn allowed_hosts(self, allowed_hosts: DomainsValidation<Host>) -> Self

Allowed hosts.

Source

pub fn session_stats<T: SessionStats>(self, stats: T) -> Self

Session stats

Source

pub fn request_middleware<T: RequestMiddleware>(self, middleware: T) -> Self

Sets a request middleware. Middleware will be invoked before each handshake request. You can either terminate the handshake in the middleware or run a default behaviour after.

Source

pub fn max_connections(self, max_connections: usize) -> Self

Maximal number of concurrent connections this server supports. Default: 100

Source

pub fn max_payload(self, max_payload_bytes: usize) -> Self

Maximal size of the payload (in bytes) Default: 5MB

Source

pub fn max_in_buffer_capacity(self, max_in_buffer_capacity: usize) -> Self

The maximum size to which the incoming buffer can grow. Default: 10,485,760

Source

pub fn max_out_buffer_capacity(self, max_out_buffer_capacity: usize) -> Self

The maximum size to which the outgoing buffer can grow. Default: 10,485,760

Source

pub fn start(self, addr: &SocketAddr) -> Result<Server>

Starts a new WebSocket server in separate thread. Returns a Server handle which closes the server when droped.

Examples found in repository?
examples/ws.rs (line 12)
4fn main() {
5	let mut io = IoHandler::default();
6	io.add_sync_method("say_hello", |_params| {
7		println!("Processing");
8		Ok(Value::String("hello".to_owned()))
9	});
10
11	let server = ServerBuilder::new(io)
12		.start(&"0.0.0.0:3030".parse().unwrap())
13		.expect("Server must start with no issues");
14
15	server.wait().unwrap()
16}

Auto Trait Implementations§

§

impl<M, S> Freeze for ServerBuilder<M, S>

§

impl<M, S> !RefUnwindSafe for ServerBuilder<M, S>

§

impl<M, S> Send for ServerBuilder<M, S>

§

impl<M, S> Sync for ServerBuilder<M, S>

§

impl<M, S> Unpin for ServerBuilder<M, S>

§

impl<M, S> !UnwindSafe for ServerBuilder<M, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V