Skip to main content

ResourceDef

Struct ResourceDef 

Source
pub struct ResourceDef<R: Resource> { /* private fields */ }
Expand description

What a Resource declares: its names, navigation, policy, tenancy, table, form, view, relations and actions.

Resource::declare returns one, and Panel::resource_with adjusts it for one panel. Every setting has a default, so a resource sets only what differs:

use tablo_core::{ReadOnly, RecordForm, Resource, ResourceDef, TernaryFilter};

impl Resource for PostResource {
    type Model = Post;
    type Form = PostForm;

    fn declare() -> ResourceDef<Self> {
        ResourceDef::new()
            .label("Blog post")
            .policy(ReadOnly)
            .table(PostForm::table().filters(TernaryFilter::new(Post::fields().featured())))
    }
}

The panel builds the def once when it mounts, binding the paths it names to the database schema, and serves the result to every request.

Implementations§

Source§

impl<R: Resource> ResourceDef<R>

Source

pub fn new() -> Self

A def with every default: the policy denies all, rows belong to no tenant, and the record form derives the table, the form and the view.

Source

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

The URL slug for the resource’s pages: "users" mounts the list at {panel prefix}/users.

Defaults to the resource type’s name without a trailing Resource, pluralized and kebab-cased: UserResource → users, BlogPostResource → blog-posts.

Source

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

One record’s name, the noun in the “Create {label}” and “Edit {label}” titles.

Defaults to the model’s type name.

Source

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

The list title and sidebar label.

Defaults to the pluralized label: Category → Categories, Person → People.

Source

pub fn icon(self, icon: IconData) -> Self

The icon of the resource’s sidebar entry.

Source

pub fn navigation_order(self, order: i32) -> Self

Where the sidebar entry sorts among the panel’s entries, lowest first; defaults to 0, and entries of equal order keep their registration order.

Source

pub fn navigation(self, item: NavigationItem) -> Self

Replaces the sidebar entry, for one that links somewhere other than the list page: NavigationItem::at("Drafts", "/admin/posts?f.status=draft").

Source

pub fn policy(self, policy: impl Policy<R::Model>) -> Self

Gates every handler; defaults to Deny. Row scoping belongs in Resource::query, not the policy.

Source

pub fn tenancy(self, tenancy: Tenancy<R::Model>) -> Self

How rows belong to a tenant; defaults to Tenancy::none.

Source

pub fn table(self, table: Table<R::Model>) -> Self

The list table; defaults to the record form’s derived table (RecordForm::table).

Source

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

The schema the create and edit forms render; defaults to the record form’s derived schema (RecordForm::schema).

The panel refuses a record form field this schema does not declare, and a schema on a resource whose Form is NoForm.

Source

pub fn view(self, view: Schema) -> Self

The read-only detail schema; defaults to the form, and an empty schema disables the detail page.

Source

pub fn relation(self, relation: Relation<R::Model>) -> Self

Adds a related resource, rendered as its table narrowed to the record on the detail and edit pages.

Source

pub fn action<A: Action<R>>(self) -> Self

Adds the custom Action A after the ones already declared.

An A::NAME that is not a single URL path segment does not compile.

Source

pub fn create_columns( self, columns: impl IntoIterator<Item = &'static str>, ) -> Self

The columns an overriding Resource::create_record sets itself, beyond the form’s fields.

Trait Implementations§

Source§

impl<R: Resource> Debug for ResourceDef<R>

Source§

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

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

impl<R: Resource> Default for ResourceDef<R>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<R> !RefUnwindSafe for ResourceDef<R>

§

impl<R> !UnwindSafe for ResourceDef<R>

§

impl<R> Freeze for ResourceDef<R>
where Arc<dyn Policy<<R as Resource>::Model>>: Freeze, Tenancy<<R as Resource>::Model>: Freeze, Option<Table<<R as Resource>::Model>>: Freeze, Vec<Relation<<R as Resource>::Model>>: Freeze, Actions<R>: Freeze,

§

impl<R> Send for ResourceDef<R>
where Arc<dyn Policy<<R as Resource>::Model>>: Send, Tenancy<<R as Resource>::Model>: Send, Option<Table<<R as Resource>::Model>>: Send, Vec<Relation<<R as Resource>::Model>>: Send, Actions<R>: Send,

§

impl<R> Sync for ResourceDef<R>
where Arc<dyn Policy<<R as Resource>::Model>>: Sync, Tenancy<<R as Resource>::Model>: Sync, Option<Table<<R as Resource>::Model>>: Sync, Vec<Relation<<R as Resource>::Model>>: Sync, Actions<R>: Sync,

§

impl<R> Unpin for ResourceDef<R>
where Arc<dyn Policy<<R as Resource>::Model>>: Unpin, Tenancy<<R as Resource>::Model>: Unpin, Option<Table<<R as Resource>::Model>>: Unpin, Vec<Relation<<R as Resource>::Model>>: Unpin, Actions<R>: Unpin,

§

impl<R> UnsafeUnpin for ResourceDef<R>

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