Skip to main content

Resource

Struct Resource 

Source
pub struct Resource {
    pub meta: ResourceMeta,
    pub fields: BTreeMap<String, Field>,
    pub permissions: Permissions,
    pub hooks: Hooks,
    pub auth: Option<AuthSpec>,
    pub admin: ResourceAdmin,
}
Expand description

A fully-parsed resource definition.

Fields§

§meta: ResourceMeta§fields: BTreeMap<String, Field>

Ordered map so generated columns/endpoints are deterministic.

§permissions: Permissions§hooks: Hooks

Named functions to run around each CRUD operation.

§auth: Option<AuthSpec>

Optional auth configuration; only meaningful on the user resource.

§admin: ResourceAdmin

How (and whether) this resource appears in the generated admin dashboard.

Implementations§

Source§

impl Resource

Source

pub fn table_name(&self) -> String

Physical table name.

Source

pub fn hook(&self, event: HookEvent) -> Option<&str>

The function bound to a lifecycle event, if any.

Source

pub fn auth_hook(&self, event: AuthEvent) -> Option<&str>

The function bound to an auth event, if any. Only meaningful on the user resource, which owns the built-in auth endpoints.

Source

pub fn validate(&self) -> Result<()>

Validate internal consistency (called after loading).

Source

pub fn admin_label(&self) -> String

Human label for a single record, e.g. "Purchase order".

Source

pub fn admin_plural(&self) -> String

Human label for the collection, e.g. "Purchase orders".

Source

pub fn admin_display_field(&self) -> Option<String>

The field whose value names a record in tables, pickers and headings.

An explicit display_field wins; otherwise the first conventionally named field (name, title, …), then the first plain string field, and finally None — at which point the dashboard falls back to the id.

Source

pub fn admin_search_field(&self) -> Option<String>

The field the dashboard’s list search box filters on.

Always a string or text column, because searching means matching part of a value: a display_field of another type names records perfectly well and simply leaves the resource without a search box.

Source

pub fn admin_columns(&self) -> Vec<String>

The columns the list table shows, in order.

Declared columns win. Otherwise: the display field first, then up to four more dashboard-visible fields, skipping json/text blobs (which never read well in a cell) and the tenancy column.

Source

pub fn references(&self) -> Vec<Reference>

All belongs_to references declared by this resource’s fields.

Source

pub fn reference_by_relation(&self, relation: &str) -> Option<Reference>

Find the reference exposed under a given relation name ("owner").

Source

pub fn is_org_scoped(&self) -> bool

Whether this resource is isolated per organisation (the default).

Source

pub fn org_column(&self) -> Option<&'static str>

The column that carries this resource’s organisation, if any: organization_id for org-scoped resources, id for the organization resource itself (its rows are organisations), else None.

Source

pub fn load(path: &Path) -> Result<Self>

Load and validate a single resource file.

Trait Implementations§

Source§

impl Clone for Resource

Source§

fn clone(&self) -> Resource

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

impl Debug for Resource

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Resource

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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<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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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