trout/
lib.rs

1//! Trout is a tree-based routing library.
2//! It is fairly generic, but designed to be used for HTTP servers.
3
4#![warn(missing_docs)]
5
6#[cfg(feature = "http02")]
7pub mod http02;
8mod internal;
9pub mod node;
10
11pub use node::Node;
12
13#[derive(Debug, Clone, Copy)]
14/// Ways that routing can fail
15pub enum RoutingFailure {
16    /// No node was found for the request path
17    NotFound,
18    /// No handler was found for the request method
19    MethodNotAllowed,
20}
21
22/// Trait to represent a Request which can be handled
23pub trait Request {
24    /// Request method, as in HTTP
25    type Method: Eq + std::hash::Hash + Clone + Send + Sync;
26
27    /// Path of request. Should *not* have a leading slash.
28    fn path<'a>(&'a self) -> &'a str;
29    /// Request method, as in HTTP
30    fn method<'a>(&'a self) -> &Self::Method;
31}
32
33impl Request for String {
34    type Method = ();
35
36    fn path(&self) -> &str {
37        &self
38    }
39
40    fn method(&self) -> &Self::Method {
41        &()
42    }
43}