Skip to main content

ServerBuilder

Struct ServerBuilder 

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

Builder for constructing a Server.

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

§Example

use eggserve_core::server::{RuntimeConfig, Server};

let server = Server::builder()
    .runtime(RuntimeConfig::default())
    .static_service("/var/www")?;

Implementations§

Source§

impl ServerBuilder

Source

pub fn runtime(self, config: RuntimeConfig) -> Self

Set the runtime configuration.

Source

pub fn serve_config(self, config: Arc<ServeConfig>) -> Self

Set a pre-built serve configuration.

This bridges the CLI/Python configuration model. The runtime config is derived from the serve config’s limits and bind address.

Source

pub fn bind(self, addr: SocketAddr) -> Self

Set the bind address for the listener.

This overrides the bind address from RuntimeConfig. The server will bind to this address when start() is called.

Source

pub fn from_listener(self, listener: TcpListener) -> Self

Use a pre-bound TCP listener instead of binding on start.

The listener must already be bound to an address. The runtime will take ownership of the listener after a successful start().

§Blocking/nonblocking

The listener should be in nonblocking mode (as returned by TcpListener::bind and TcpListener::from_std). The runtime will normalize to nonblocking if needed.

§Ownership

After start(), the runtime owns the listener. The caller must not use the listener after passing it to the builder.

Source

pub fn build(self) -> Result<Server, ServerError>

Build the server, eagerly constructing the built-in static file service when a serve configuration was supplied.

Invalid static roots therefore fail during build(), before listener preparation or startup. The serve config must have been set via ServerBuilder::serve_config for Server::start to be available.

Source

pub fn static_service( self, root: impl AsRef<Path>, ) -> Result<Server, ServerError>

Build the server with a static service rooted at the given path.

Convenience method that creates both the serve config and runtime config.

Trait Implementations§

Source§

impl Debug for ServerBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.