pub struct RouteCtx { /* private fields */ }Expand description
What a contributed route is given at boot.
Deliberately narrow: the admin’s own router state stays private, so its
composition can change without breaking a screen. Fields are read through
accessors, so this can gain context after 1.0; new cannot, and extra context
would arrive as a builder.
Implementations§
Source§impl RouteCtx
impl RouteCtx
pub fn db(&self) -> &Db
Sourcepub fn form(&self, path: &str) -> Option<FormHandle>
pub fn form(&self, path: &str) -> Option<FormHandle>
A resource’s form, to write its records from code: an importer, a sync, anything that saves what an operator could have typed.
path is the resource’s path as its descriptor declares it, relative to
the admin root (/products). None when no resource mounts there or the
one that does has no form. The handle is Clone and owns what it needs,
so a detached task may keep it.
Sourcepub fn events(&self) -> &Events
pub fn events(&self) -> &Events
The application’s event bus, for a route that announces a fact:
ctx.events().emit(&Published { article_id }).await. Clone it into the
route’s state.
Sourcepub fn base_url(&self) -> &str
pub fn base_url(&self) -> &str
The site’s own origin, without a trailing slash: the configured
app.url, falling back to the bind address when none is declared.
For the absolute URLs a route has to emit rather than link: a <loc> in a
sitemap, a canonical URL, an entry in a feed. The request’s Host header
is not a substitute, because behind a proxy it is whatever the proxy sent.
Sourcepub fn contributions<T: Send + Sync + 'static>(&self) -> Vec<&T>
pub fn contributions<T: Send + Sync + 'static>(&self) -> Vec<&T>
The contributions of type T that the framework itself does not consume.
This is how one module reads another’s contributions. A module declaring
its own kind of extension point defines a type, other modules contribute
it from their register, and the route reads them here: the framework
never learns the type, and registration order does not matter because
everything is collected before any route runs.
Sourcepub fn base_path(&self) -> &str
pub fn base_path(&self) -> &str
Where this screen actually mounted, after the module namespace, any base it declared, the deployment’s overrides and the admin mount.
Sourcepub fn admin_path(&self) -> &str
pub fn admin_path(&self) -> &str
Where the admin panel is mounted, after backend.path. Ask rather than
assuming /admin: an operator may have moved it, and a module building a
link into the panel, or excluding it from a sitemap, needs the real one.
Sourcepub fn url(&self, relative: &str) -> String
pub fn url(&self, relative: &str) -> String
An absolute admin URL under this screen. Build every self-link this way: a deployment can move the screen, so a hardcoded path would break.
Sourcepub fn builder(db: Db) -> RouteCtxBuilder
pub fn builder(db: Db) -> RouteCtxBuilder
A context built by hand, for testing a route without booting the framework.
mount takes a RouteCtx, and the framework’s own constructor is private,
so without this a plugin could only exercise its routes through a full boot.
With it, a route is an ordinary tower service:
let ctx = RouteCtx::builder(db).admin_path("/backoffice").build();
let response = MyRoute.mount(&ctx).oneshot(request).await?;This is also how the context grows after 1.0: a new field gets a builder
method and a default, which new could not have offered.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for RouteCtx
impl !UnwindSafe for RouteCtx
impl Freeze for RouteCtx
impl Send for RouteCtx
impl Sync for RouteCtx
impl Unpin for RouteCtx
impl UnsafeUnpin for RouteCtx
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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 more