pub struct UnifiedRouter { /* private fields */ }client-router only.Expand description
Unified router combining server and client routing capabilities.
This struct provides a unified interface for configuring both:
- Server-side routes: HTTP methods, middleware, DI, ViewSets
- Client-side routes: SPA navigation, history API,
Pagerendering
§Example
use reinhardt_urls::routers::UnifiedRouter;
use reinhardt_core::page::Page;
let router = UnifiedRouter::new()
.server(|s| s.function("/api/health", Method::GET, health_handler))
.client(|c| c.route("/", || home_page()));Implementations§
Source§impl UnifiedRouter
impl UnifiedRouter
Sourcepub fn new() -> UnifiedRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn new() -> UnifiedRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Creates a new UnifiedRouter with default server and client routers.
Sourcepub fn server<F>(self, f: F) -> UnifiedRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn server<F>(self, f: F) -> UnifiedRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Configure server-side routing with a closure.
The closure receives a ServerRouter and should return a configured router.
§Example
let router = UnifiedRouter::new()
.server(|s| s
.with_prefix("/api")
.function("/users", Method::GET, list_users));Sourcepub fn client<F>(self, f: F) -> UnifiedRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn client<F>(self, f: F) -> UnifiedRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Configure client-side routing with a closure.
The closure receives a ClientRouter and should return a configured router.
§Example
let router = UnifiedRouter::new()
.client(|c| c
.route("/", || home_page())
.route_path("/users/{id}", |Path(id): Path<i64>| user_page(id)));Sourcepub fn server_ref(&self) -> &ServerRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn server_ref(&self) -> &ServerRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Returns a reference to the server router.
Sourcepub fn server_mut(&mut self) -> &mut ServerRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn server_mut(&mut self) -> &mut ServerRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Returns a mutable reference to the server router.
Sourcepub fn client_ref(&self) -> &ClientRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn client_ref(&self) -> &ClientRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Returns a reference to the client router.
Sourcepub fn client_mut(&mut self) -> &mut ClientRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn client_mut(&mut self) -> &mut ClientRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Returns a mutable reference to the client router.
Sourcepub fn into_server(self) -> ServerRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn into_server(self) -> ServerRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Consumes the router and returns the server router.
If this router has a DI context, deferred DI registrations are applied directly to its singleton scope. Otherwise they are stashed in the global registry for later application by the server.
Sourcepub fn into_client(self) -> ClientRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn into_client(self) -> ClientRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Consumes the router and returns the client router.
Sourcepub fn into_parts(self) -> (ServerRouter, ClientRouter)
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn into_parts(self) -> (ServerRouter, ClientRouter)
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Consumes the router and returns both parts.
Sourcepub fn register_globally(self) -> ClientRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn register_globally(self) -> ClientRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Registers server router globally and returns client router.
This is a convenience method for full-stack applications that need to:
- Register the server router globally for HTTP request handling
- Keep the client router for SPA navigation
§Example
let client = UnifiedRouter::new()
.server(|s| s.function("/api/data", Method::GET, handler))
.client(|c| c.route("/", || home_page()))
.register_globally();
// Server router is now globally registered
// Client router is returned for SPA useSourcepub fn with_di_registrations(self, list: DiRegistrationList) -> UnifiedRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn with_di_registrations(self, list: DiRegistrationList) -> UnifiedRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Attach deferred DI registrations to this router.
When the router is consumed, these registrations are applied directly
to the DI context’s singleton scope if one has been set via
with_di_context. Otherwise they are stashed
globally for later application (e.g., by the runall command).
Sourcepub fn with_prefix(self, prefix: impl Into<String>) -> UnifiedRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn with_prefix(self, prefix: impl Into<String>) -> UnifiedRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Set URL prefix for server router.
This is a convenience method that delegates to ServerRouter::with_prefix.
Sourcepub fn with_namespace(self, namespace: impl Into<String>) -> UnifiedRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn with_namespace(self, namespace: impl Into<String>) -> UnifiedRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Set namespace for server router.
This is a convenience method that delegates to ServerRouter::with_namespace.
Sourcepub fn with_di_context(self, ctx: Arc<InjectionContext>) -> UnifiedRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn with_di_context(self, ctx: Arc<InjectionContext>) -> UnifiedRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Set DI context for server router.
This is a convenience method that delegates to ServerRouter::with_di_context.
Sourcepub fn with_middleware<M>(self, middleware: M) -> UnifiedRouterwhere
M: Middleware + 'static,
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn with_middleware<M>(self, middleware: M) -> UnifiedRouterwhere
M: Middleware + 'static,
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Add middleware to server router.
This is a convenience method that delegates to ServerRouter::with_middleware.
Sourcepub fn exclude(self, pattern: &str) -> UnifiedRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn exclude(self, pattern: &str) -> UnifiedRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Exclude a URL path from the most recently added server middleware.
This is a convenience method that delegates to ServerRouter::exclude.
Sourcepub fn mount(self, prefix: &str, child: ServerRouter) -> UnifiedRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn mount(self, prefix: &str, child: ServerRouter) -> UnifiedRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Mount a child server router on this router.
This is a convenience method that delegates to ServerRouter::mount.
Sourcepub fn mount_unified(self, prefix: &str, child: UnifiedRouter) -> UnifiedRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn mount_unified(self, prefix: &str, child: UnifiedRouter) -> UnifiedRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Mount a child UnifiedRouter on this router.
Extracts the server router from the child and mounts it.
Sourcepub fn endpoint<F, E>(self, f: F) -> UnifiedRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn endpoint<F, E>(self, f: F) -> UnifiedRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Register an endpoint on server router.
This is a convenience method that delegates to ServerRouter::endpoint.
Sourcepub fn function<F, Fut>(
self,
path: &str,
method: Method,
func: F,
) -> UnifiedRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn function<F, Fut>( self, path: &str, method: Method, func: F, ) -> UnifiedRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Register a function-based route on server router.
This is a convenience method that delegates to ServerRouter::function.
Sourcepub fn function_named<F, Fut>(
self,
path: &str,
method: Method,
name: &str,
func: F,
) -> UnifiedRouter
Available on crate feature test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.
pub fn function_named<F, Fut>( self, path: &str, method: Method, name: &str, func: F, ) -> UnifiedRouter
test and non-WebAssembly and (non-WebAssembly or crate feature client-router) only.Register a named function-based route on server router.
This is a convenience method that delegates to ServerRouter::function_named.
Trait Implementations§
Source§impl DeeplinkRouterExt for UnifiedRouter
impl DeeplinkRouterExt for UnifiedRouter
Source§type Output = UnifiedRouter
type Output = UnifiedRouter
Source§fn with_deeplinks(
self,
config: DeeplinkConfig,
) -> Result<UnifiedRouter, DeeplinkError>
fn with_deeplinks( self, config: DeeplinkConfig, ) -> Result<UnifiedRouter, DeeplinkError>
Source§impl Default for UnifiedRouter
Available on non-WebAssembly only.
impl Default for UnifiedRouter
Source§fn default() -> UnifiedRouter
fn default() -> UnifiedRouter
Auto Trait Implementations§
impl !Freeze for UnifiedRouter
impl !RefUnwindSafe for UnifiedRouter
impl !Send for UnifiedRouter
impl !Sync for UnifiedRouter
impl Unpin for UnifiedRouter
impl UnsafeUnpin for UnifiedRouter
impl !UnwindSafe for UnifiedRouter
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.