Skip to main content

Server

Struct Server 

Source
pub struct Server { /* private fields */ }
Expand description

A reusable HTTP runtime server.

This type is experimental and its API may change without notice.

The server binds a TCP listener, accepts connections, and dispatches them to a Service implementation. It owns the full connection lifecycle: parsing, normalization, timeouts, connection tracking, and graceful shutdown.

§Example

use eggserve_core::server::{Server, RuntimeConfig, service_fn, Request};
use eggserve_core::primitives::canonical::{Response, StatusCode, ResponseBody};

let server = Server::builder()
    .runtime(RuntimeConfig::builder()
        .bind("127.0.0.1:8000".parse().unwrap())
        .build()?)
    .build()?;

let handle = server.start_with_service(service_fn(|_req: Request| async {
    Ok(Response::builder()
        .status(StatusCode::OK)
        .body(ResponseBody::Bytes(b"hello".to_vec()))
        .unwrap())
})).await?;
handle.ready().await?;
println!("listening on {}", handle.local_addr());

// ... serve requests ...

handle.shutdown();
handle.wait().await?;

Implementations§

Source§

impl Server

Source

pub fn builder() -> ServerBuilder

Create a new server builder with default configuration.

Source§

impl Server

Source

pub async fn start(self) -> Result<ServerHandle, ServerError>

Start the server with the built-in static file service.

Starts the statically constructed service using the shared generic accept loop. The serve config must have been set via ServerBuilder::serve_config.

Source

pub async fn start_with_service<S: Service>( self, service: S, ) -> Result<ServerHandle, ServerError>

Start the server with a custom service.

The custom service does not require a static root or serve configuration. The runtime creates only transport state (semaphores, lifecycle) and passes it to the accept loop and connection pipeline.

Auto Trait Implementations§

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<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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, 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.