pub struct ServerBuilder { /* private fields */ }Implementations§
Source§impl ServerBuilder
impl ServerBuilder
Sourcepub fn config(self, cfg: Config) -> Self
pub fn config(self, cfg: Config) -> Self
Bulk-applies a loaded Config (e.g. from nitr.toml).
Setters called afterwards override it.
Sourcepub fn listen(self, addr: SocketAddr) -> Self
pub fn listen(self, addr: SocketAddr) -> Self
Address the server binds to.
Sourcepub fn listener(self, listener: TcpListener) -> Self
pub fn listener(self, listener: TcpListener) -> Self
Serves on an already-bound listener instead of binding
listen.
This closes the window between choosing a port and binding it: a caller can bind port 0 (the OS picks a free one), read the real address, and hand the listener over — nothing else can take the port in between. That makes it the right tool for tests and for socket-activation setups where the supervisor owns the socket.
Sourcepub fn health_listener(self, listener: TcpListener) -> Self
pub fn health_listener(self, listener: TcpListener) -> Self
Serves the health probes on an already-bound listener instead of
binding [health] bind.
The probe-port counterpart of listener, closing
the same choose-then-bind window: reserve port 0, read the real
address, hand the listener over. Ignored when [health] enabled
is off.
Sourcepub fn handler_script(self, path: impl Into<PathBuf>) -> Self
pub fn handler_script(self, path: impl Into<PathBuf>) -> Self
The handler script, loaded once per Lua state at startup and on every reload; its routes serve the requests.
Sourcepub fn config_script(self, path: impl Into<PathBuf>) -> Self
pub fn config_script(self, path: impl Into<PathBuf>) -> Self
Lua script executed exactly once at startup; its returned table is passed to the handler on every request.
Sourcepub fn templates_dir(self, path: impl Into<PathBuf>) -> Self
pub fn templates_dir(self, path: impl Into<PathBuf>) -> Self
Directory for the template builtin ([templating] dir).
Sourcepub fn database(self, path: impl Into<PathBuf>) -> Self
pub fn database(self, path: impl Into<PathBuf>) -> Self
SQLite database file for the conn builtin.
Sourcepub fn builtins(self, builtins: Builtins) -> Self
pub fn builtins(self, builtins: Builtins) -> Self
Standard library (nitr.*) features to expose; overrides the
[std] features list from the configuration file. Without either,
the minimal default set (Builtins::minimal()) is enabled.
Sourcepub fn workers(self, n: usize) -> Self
pub fn workers(self, n: usize) -> Self
Number of pooled Lua states (max concurrently executing handlers).
Sourcepub fn dev_mode(self, on: bool) -> Self
pub fn dev_mode(self, on: bool) -> Self
Development mode: hot-reload the handler script on change.
Sourcepub fn module<F>(self, name: impl Into<String>, f: F) -> Self
pub fn module<F>(self, name: impl Into<String>, f: F) -> Self
Registers a Rust extension module: the closure runs once per pooled
state (and again on every reload) and its returned table is mounted
at nitr.ext.<name> — one level below the standard library, so a
module can never collide with a builtin (present or future).
Registration fails at build time when two modules share a name.
// Scripts call it as nitr.ext.greet.hello("world").
Server::builder().module("greet", |lua| {
let t = lua.create_table()?;
t.set("hello", lua.create_function(|_, name: String| {
Ok(format!("Hello, {name}!"))
})?)?;
Ok(t)
})Sourcepub fn cache(self, cache: Cache) -> Self
pub fn cache(self, cache: Cache) -> Self
The storage behind nitr.cache, instead of a fresh one sized by
[cache]. nitr test hands its test states the same instance, so
what a handler caches is observable from a test. Unused when the
cache builtin is not enabled.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ServerBuilder
impl !UnwindSafe for ServerBuilder
impl Freeze for ServerBuilder
impl Send for ServerBuilder
impl Sync for ServerBuilder
impl Unpin for ServerBuilder
impl UnsafeUnpin 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more