Skip to main content

Resource

Struct Resource 

Source
#[non_exhaustive]
pub struct Resource { pub base_path: String, pub nav_label: Text, pub list: ListConfig, pub form: Option<FormConfig>, pub permission: Option<String>, pub import: Option<ImportConfig>, pub relations: Vec<RelationConfig>, }
Expand description

An admin resource: a list screen, optionally with a create/edit form, mounted under base_path and shown in the menu as nav_label.

Built with Resource::new plus its builder methods. Non-exhaustive because this is the descriptor a plugin author writes and the one most likely to grow: a struct literal outside this crate would freeze its field set at 1.0, so the framework could never learn anything new about a resource.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§base_path: String

The path the resource mounts at, relative to the admin root and starting with a slash (e.g. /products). The framework prepends the configured admin mount, so a resource never hardcodes it and survives a moved panel. The list’s edit_base and the form’s base_path are resolved the same way.

§nav_label: Text

The menu label, localized at render. Serde stays a plain string.

§list: ListConfig§form: Option<FormConfig>§permission: Option<String>

The permission an operator must hold to reach any of the resource’s routes. A dotted string gates every route the resource mounts, and an operator who lacks it receives 403 Forbidden; superusers pass regardless. None leaves the resource open to any signed-in operator and is allowed only for a read-only resource: a resource with a create/edit form must declare a permission, or boot aborts (see [mount_resource]).

§import: Option<ImportConfig>

Whether records may be imported into this resource, and by whom. The pages mount under the resource’s path; see import.

§relations: Vec<RelationConfig>

Other entities’ records that belong to each of this resource’s records, each a section on the edit page. See relation::RelationConfig.

Implementations§

Source§

impl Resource

Source

pub fn new( base_path: impl Into<String>, nav_label: impl Into<Text>, list: ListConfig, ) -> Self

A read-only resource: a list at base_path, in the menu as nav_label.

A create/edit form is added with Resource::form, which also requires Resource::permission: an unguarded write resource aborts boot.

Source

pub fn relation(self, relation: RelationConfig) -> Self

Adds a section of related records to the edit page. Needs a form.

Source

pub fn import(self, import: ImportConfig) -> Self

Lets records be imported into this resource, which needs a form.

Source

pub fn form(self, form: FormConfig) -> Self

Adds the create/edit form. A resource with one must also declare a permission, or boot aborts.

Source

pub fn permission(self, permission: impl Into<String>) -> Self

The permission gating every route this resource mounts.

Trait Implementations§

Source§

impl Serialize for Resource

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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