Trait front_line::Router
source · pub trait Router<'de>: Sized {
// Required method
fn handle_parsed(method: Method, remaining_path: &'de str) -> Option<Self>;
// Provided method
fn resolve(request: &'de [u8]) -> Result<RouterResult<'de, Self>, Error> { ... }
}
Expand description
A trait that encapsulates routing logic for an HTTP request.
Implementers of this trait can specify custom logic to handle parsed method and path segments,
allowing for flexible routing mechanisms. However, for most common use cases, it’s recommended
to use the front_line::FrontLine
proc-macro to auto-generate Router
instances for enums.
The provided route
method processes an HTTP request byte slice, parsing its method, path, and
query components. If parsing is successful, it constructs a RouterResult
that encapsulates
these parsed components.
Required Methods§
sourcefn handle_parsed(method: Method, remaining_path: &'de str) -> Option<Self>
fn handle_parsed(method: Method, remaining_path: &'de str) -> Option<Self>
Handle the parsed method and path segment.
Implementers can provide custom logic to identify routes based on the parsed method and path. This allows for the identification of specific application routes, endpoints, etc.
Arguments
method
- The parsed HTTP method (e.g., GET, POST).remaining_path
- The parsed path segment from the HTTP request.
Returns
Returns an instance of the implementing type if a route is identified. Otherwise,
returns None
.
Provided Methods§
sourcefn resolve(request: &'de [u8]) -> Result<RouterResult<'de, Self>, Error>
fn resolve(request: &'de [u8]) -> Result<RouterResult<'de, Self>, Error>
Parse and route an HTTP request.
This method provides the core logic to process an HTTP request byte slice, extract its components, and identify a route if possible.
Arguments
request
- The raw byte slice of the HTTP request.
Returns
Returns a Result
containing the RouterResult
if routing is successful. If any parsing
or validation errors occur, returns an Error
.