pub struct ServerBuilder { /* private fields */ }Expand description
Server builder for configuring the runtime.
Implementations§
Source§impl ServerBuilder
impl ServerBuilder
Sourcepub fn with_config(self, cfg: ServerConfig) -> Self
pub fn with_config(self, cfg: ServerConfig) -> Self
Apply a custom server configuration.
Sourcepub fn with_graceful_shutdown<F>(self, fut: F) -> Self
pub fn with_graceful_shutdown<F>(self, fut: F) -> Self
Provide a future to trigger graceful shutdown.
Examples found in repository?
examples/history.rs (lines 51-53)
40pub async fn main() -> Result<()> {
41 let addr = env::args()
42 .nth(1)
43 .unwrap_or_else(|| "0.0.0.0:6379".to_string());
44
45 let app = Router::from_state(AppState::default())
46 .route("HISTORY", history)
47 .route("COMMAND", history)
48 .route("PING", ping);
49
50 Server::bind(&addr)
51 .with_graceful_shutdown(async {
52 let _ = signal::ctrl_c().await;
53 })
54 .serve(app)
55 .await
56}Sourcepub fn with_hooks<H>(self, hooks: H) -> Selfwhere
H: ServerHooks,
pub fn with_hooks<H>(self, hooks: H) -> Selfwhere
H: ServerHooks,
Provide observability hooks for the server runtime.
Sourcepub fn with_connection_extensions<F>(self, factory: F) -> Self
pub fn with_connection_extensions<F>(self, factory: F) -> Self
Provide per-connection extensions for request contexts.
The factory is invoked once per connection and its Extensions are
cloned into each RequestContext for that connection.
Sourcepub async fn serve<State>(self, app: Router<State>) -> Result<()>
pub async fn serve<State>(self, app: Router<State>) -> Result<()>
Examples found in repository?
More examples
examples/history.rs (line 54)
40pub async fn main() -> Result<()> {
41 let addr = env::args()
42 .nth(1)
43 .unwrap_or_else(|| "0.0.0.0:6379".to_string());
44
45 let app = Router::from_state(AppState::default())
46 .route("HISTORY", history)
47 .route("COMMAND", history)
48 .route("PING", ping);
49
50 Server::bind(&addr)
51 .with_graceful_shutdown(async {
52 let _ = signal::ctrl_c().await;
53 })
54 .serve(app)
55 .await
56}Sourcepub async fn serve_with_listener<State>(
self,
listener: TcpListener,
app: Router<State>,
) -> Result<()>
pub async fn serve_with_listener<State>( self, listener: TcpListener, app: Router<State>, ) -> Result<()>
Serve using a pre-bound listener (useful for tests).
Auto Trait Implementations§
impl Freeze for ServerBuilder
impl !RefUnwindSafe for ServerBuilder
impl Send for ServerBuilder
impl !Sync for ServerBuilder
impl Unpin for ServerBuilder
impl !UnwindSafe for ServerBuilder
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