Skip to main content

ResourceKind

Struct ResourceKind 

Source
pub struct ResourceKind { /* private fields */ }
Expand description

One resource type with its type erased: what Resource offers, reached by the kind a record names. See the module docs.

Implementations§

Source§

impl ResourceKind

Source

pub const fn of<R: Resource>() -> Self

R, by its kind, published by the app it declares (Resource::APP_ID) unless the caller hosts it for another (Self::hosted_by).

Source

pub const fn hosted_by(self, app_id: &'static str, title: &'static str) -> Self

The app that hosts records of this kind: its id, which permissions name, and its title.

Source

pub const fn of_effect<V: Effect>( kind: &'static str, label: &'static str, app: &'static str, ) -> Self

A kind for an effect vocabulary, which publishes no record of its own and reaches state through the record an effect addresses: kind is the operation its effects travel under and app the app that offers them. What an effect’s ActionRef carries.

Source

pub const fn declaring<R>(app: &'static str, title: &'static str) -> Self
where R: Resource,

R’s kind as the app app declares it: hosted by it, naming its records as the resource itself does, and built from the type’s name alone — so a typed ActionRef carries it as a constant and ActionRef::key names the app, kind and action a control is bound against. Nothing is registered, so it costs an app no initialisation.

Source

pub const fn declared<R>( kind: &'static str, label: &'static str, app: &'static str, ) -> Self
where R: Resource,

Self::declaring for a kind built where R may still be defined: the kind, label and app the declaration wrote. A resource publishes its own kind from Self::of, so a control bound by key reads the same kind either way.

Source

pub fn declaring_app(&self) -> &'static str

The app this kind names its actions by: the one hosting it, else DEFAULT_APP for a resource type that declares no app of its own.

Source

pub const fn declares(app: &str, declared: &str) -> bool

Whether app is the app declared names, or the type declared none and app is the default. What a generated ActionRef asks at compile time before it carries app, so a constant naming another app than its type’s fails where it is written rather than at the control that binds it.

Source

pub const fn named(self, name: fn(&dyn Any) -> Option<String>) -> Self

What an open resource of this kind is called, read from its state (a document’s first heading). name answers None for a state of another type. Defaults to the resource’s Resource::LABEL.

Source

pub fn kind(&self) -> &'static str

The kind records of this type name, e.g. "notes.notebook".

Source

pub fn label(&self) -> &'static str

The human name of one resource of this kind.

Source

pub fn action_type(&self) -> &'static str

The registry type id its actions replay under.

Source

pub fn lands(&self, doc: &Doc, action: &EncodedAction) -> Option<Place>

Where action of this kind, just applied to doc, leaves the member who took it (Resource::lands); None for an action of another type or one that lands nowhere in particular. A group lands where its last member does.

Source

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

The id of the app hosting it, when one registered it.

Source

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

The title of the app hosting it, when one registered it.

Source

pub fn version(&self) -> u32

The storage version the resource reads; an older record is brought up to it when it opens (crate::evolution).

Source

pub fn read(&self, doc: &Doc) -> Result<Box<dyn Any>, ModelError>

The state views render, read from doc; downcast it to the resource’s State where the type is known.

§Errors

Returns ModelError when the document does not hold this resource.

Source

pub fn read_as<S: 'static>(&self, doc: &Doc) -> Result<S, ModelError>

Self::read as the state type the caller expects.

§Errors

Returns ModelError when the document does not hold this resource or its state is not an S.

Source

pub fn holds(&self, doc: &Doc) -> bool

Whether doc holds a resource of this kind: its own read accepts it.

Source

pub fn holds_or_older(&self, doc: &Doc) -> bool

Whether doc holds a resource of this kind, or was kept before the app changed its storage and is brought up to it when it opens: a workspace still keeps the older document after a replica migrated its own.

Source

pub fn name(&self, state: &dyn Any) -> String

What the open resource is called, from a state Self::read returned.

Source

pub fn publish(&self, id: &str, doc: &Doc) -> Result<ResourceSpec, ModelError>

The tree published for the resource doc holds, under id: every declared and state-bound action, the generic apply and group actions, its views and its nested resources — what publish builds for the typed resource.

§Errors

Returns ModelError when the document does not hold this resource.

Source

pub fn child( &self, doc: &Doc, id: &str, ) -> Result<Option<ResourceSpec>, ModelError>

Read one existing lazy child from the publishing resource’s own resolver. This returns metadata only and never creates or invokes the child.

Source

pub fn content( &self, doc: &Doc, item: Option<&str>, ) -> Result<Value, ModelError>

What doc holds, as JSON a caller can act on: the resource itself, or with item, the part of it that id names — the reading a document host offers a view (docs/architecture/apps.md §2). Read through the type’s own Resource::read_content where it answers reads, else from the record’s model tables, so a host that links no model type still reads exactly what the app’s process did.

§Errors

Returns ModelError when the document does not hold this resource, or a refusal naming why the part cannot be read.

Source

pub fn reads_item(&self, item: &str) -> bool

Whether Self::content answers with item: the record publishes a read of that part.

Source

pub fn opens_as_item(&self, id: &str) -> bool

Whether the resource id is an item this kind’s window shows with an open of its own (opens_as_item).

Source

pub fn publish_state( &self, id: &str, state: &dyn Any, ) -> Result<ResourceSpec, ModelError>

Self::publish from a state Self::read returned.

§Errors

Returns ModelError when state is not this resource’s state.

Source

pub fn to_json(&self, state: &dyn Any) -> Result<Value, ModelError>

What the state a Self::read returned is, as JSON: the reading a view of the resource is offered, where no better adapter answers.

§Errors

Returns ModelError when state is not this resource’s state.

Source

pub fn search(&self, doc: &Doc) -> Result<Vec<SearchEntry>, ModelError>

Entries for the system search index.

§Errors

Returns ModelError when the document does not hold this resource.

Source

pub fn register(&self, registry: &mut ActionRegistry)

Register what a replica of this kind replays: the resource’s actions and groups of them.

Source

pub fn initialize(&self, doc: &mut Doc) -> Result<(), ModelError>

Write a brand-new record’s genesis (Resource::initialize).

Source

pub fn rewrite(&self, doc: &mut Doc, from: u32) -> Result<(), ModelError>

The app’s own rewrite of a record of this kind from the version it stood at (crate::evolution::rewrite), which follows its derived steps.

§Errors

Returns the migration’s error.

Source

pub fn needs_migrate(&self, doc: &Doc) -> bool

Whether doc is older than this kind: its chain of steps stops short of this kind’s version.

Source

pub fn encode(&self, action: Value) -> Result<EncodedAction, String>

One typed action from its JSON form, encoded for replay — read as the generic apply action reads it, so a value naming a declared action is checked against that declaration.

Trait Implementations§

Source§

impl Clone for ResourceKind

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

impl Copy for ResourceKind

Source§

impl Debug for ResourceKind

Source§

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

Formats the value using the given formatter. 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> 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> 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> 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