Skip to main content

RouteCtx

Struct RouteCtx 

Source
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

Source

pub async fn audit( &self, user: &AuthenticatedUser, action: &str, target_type: Option<&str>, target_id: Option<&str>, target_label: Option<&str>, detail: Option<&str>, )

Appends one audit entry for a mutation user just performed through a module’s own screen. A failed write is logged and never fails the operation it records.

Source

pub fn value_form( &self, fields: &[FormField], scope: &str, ) -> Result<ValueForm, Text>

A form over a JSON object from fields, rendered and collected through the registered field types; scope names what an override is scoped to. Refused, naming the field, when a type is unregistered or an option malformed: the fields may come from data edited at runtime.

Source

pub fn db(&self) -> &Db

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Clone for RouteCtx

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more