Skip to main content

WebIo

Struct WebIo 

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

The central Application controller. Manages routing, middleware, and the internal TCP lifecycle.

Implementations§

Source§

impl WebIo

Source

pub fn new() -> Self

Initializes a new WebIo instance with an empty routing table.

Source

pub fn use_mw<F>(&mut self, f: F)
where F: Fn(&str) -> Option<Reply> + Send + Sync + 'static,

Registers a global middleware function. If the middleware returns Some(Reply), the request cycle ends early.

Source

pub fn on_404<F, Fut>(&mut self, handler: F)
where F: Fn(Req, Params) -> Fut + Send + Sync + 'static, Fut: Future<Output = Reply> + Send + 'static,

Configures custom 404 handlers. It intelligently detects Content-Type to serve JSON or HTML based on the client’s Accept header.

Source

pub fn route<F, Fut>(&mut self, method: Method, path: &str, handler: F)
where F: Fn(Req, Params) -> Fut + Send + Sync + 'static, Fut: Future<Output = Reply> + Send + 'static,

Supports dynamic segments using <name> syntax (e.g., /user/<id>).

Source

pub async fn run(self, host: &str, port: &str)

Starts the blocking TCP listener loop. Spawns a new thread per connection to maintain responsiveness.

Auto Trait Implementations§

§

impl Freeze for WebIo

§

impl !RefUnwindSafe for WebIo

§

impl Send for WebIo

§

impl Sync for WebIo

§

impl Unpin for WebIo

§

impl !UnwindSafe for WebIo

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