pub struct Server { /* private fields */ }Expand description
Low-level multi-threaded server.
Use this when you want full control over the Router (e.g. adding
middleware, merging sub-routers) instead of the macro-driven Chopin
builder.
§Example
ⓘ
use chopin_core::{Router, Server, Context, Response};
fn ping(_ctx: Context) -> Response { Response::text("pong") }
let mut router = Router::new();
router.get("/ping", ping);
Server::bind("0.0.0.0:8080")
.workers(4)
.serve(router)
.unwrap();Implementations§
Source§impl Server
impl Server
Sourcepub fn bind(host_port: &str) -> Self
pub fn bind(host_port: &str) -> Self
Bind to the given address. Defaults to one worker per logical CPU.
Sourcepub fn workers(self, workers: usize) -> Self
pub fn workers(self, workers: usize) -> Self
Set the number of worker threads (defaults to num_cpus::get()).
Sourcepub fn serve(self, router: Router) -> ChopinResult<()>
pub fn serve(self, router: Router) -> ChopinResult<()>
Start the server with the provided router. Spawns one thread per worker, each pinned to a CPU core, and blocks until shutdown.
Auto Trait Implementations§
impl Freeze for Server
impl RefUnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
impl UnwindSafe for Server
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more