pub struct VesperaRouter<S>{ /* private fields */ }Expand description
A router wrapper that defers merging until with_state() is called.
This is necessary because in Axum, routers can only be merged when they have the same state type. By deferring the merge, we ensure that:
- The base router’s
.with_state()is called first, converting it toRouter<()> - Then the child routers (also
Router<()>) are merged
This wrapper is returned by vespera!() when the merge parameter is used.
Implementations§
Source§impl<S> VesperaRouter<S>
impl<S> VesperaRouter<S>
Sourcepub fn new(base: Router<S>, merge_fns: Vec<fn() -> Router<()>>) -> Self
pub fn new(base: Router<S>, merge_fns: Vec<fn() -> Router<()>>) -> Self
Create a new VesperaRouter with a base router and routers to merge
Sourcepub fn with_state(self, state: S) -> Router<()>
pub fn with_state(self, state: S) -> Router<()>
Provide the state for the router and merge all child routers.
This is equivalent to calling Router::with_state() and then merging
all the child routers.
After calling with_state(), the router’s state type becomes () because
the state has been provided. Child routers (also Router<()>) can then be merged.
Sourcepub fn layer<L>(self, layer: L) -> Selfwhere
L: Layer<Route> + Clone + Send + Sync + 'static,
L::Service: Service<Request> + Clone + Send + Sync + 'static,
<L::Service as Service<Request>>::Response: IntoResponse + 'static,
<L::Service as Service<Request>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request>>::Future: Send + 'static,
pub fn layer<L>(self, layer: L) -> Selfwhere
L: Layer<Route> + Clone + Send + Sync + 'static,
L::Service: Service<Request> + Clone + Send + Sync + 'static,
<L::Service as Service<Request>>::Response: IntoResponse + 'static,
<L::Service as Service<Request>>::Error: Into<Infallible> + 'static,
<L::Service as Service<Request>>::Future: Send + 'static,
Add a layer to the router.
Auto Trait Implementations§
impl<S> Freeze for VesperaRouter<S>
impl<S> !RefUnwindSafe for VesperaRouter<S>
impl<S> Send for VesperaRouter<S>
impl<S> Sync for VesperaRouter<S>
impl<S> Unpin for VesperaRouter<S>
impl<S> !UnwindSafe for VesperaRouter<S>
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
Mutably borrows from an owned value. Read more