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
impl ResourceKind
Sourcepub const fn of<R: Resource>() -> Self
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).
Sourcepub const fn hosted_by(self, app_id: &'static str, title: &'static str) -> Self
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.
Sourcepub const fn of_effect<V: Effect>(
kind: &'static str,
label: &'static str,
app: &'static str,
) -> Self
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.
Sourcepub const fn declaring<R>(app: &'static str, title: &'static str) -> Selfwhere
R: Resource,
pub const fn declaring<R>(app: &'static str, title: &'static str) -> Selfwhere
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.
Sourcepub const fn declared<R>(
kind: &'static str,
label: &'static str,
app: &'static str,
) -> Selfwhere
R: Resource,
pub const fn declared<R>(
kind: &'static str,
label: &'static str,
app: &'static str,
) -> Selfwhere
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.
Sourcepub fn declaring_app(&self) -> &'static str
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.
Sourcepub const fn named(self, name: fn(&dyn Any) -> Option<String>) -> Self
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.
Sourcepub fn action_type(&self) -> &'static str
pub fn action_type(&self) -> &'static str
The registry type id its actions replay under.
Sourcepub fn lands(&self, doc: &Doc, action: &EncodedAction) -> Option<Place>
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.
Sourcepub fn app_id(&self) -> Option<&'static str>
pub fn app_id(&self) -> Option<&'static str>
The id of the app hosting it, when one registered it.
Sourcepub fn app_title(&self) -> Option<&'static str>
pub fn app_title(&self) -> Option<&'static str>
The title of the app hosting it, when one registered it.
Sourcepub fn version(&self) -> u32
pub fn version(&self) -> u32
The storage version the resource reads; an older record is brought
up to it when it opens (crate::evolution).
Sourcepub fn read(&self, doc: &Doc) -> Result<Box<dyn Any>, ModelError>
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.
Sourcepub fn read_as<S: 'static>(&self, doc: &Doc) -> Result<S, ModelError>
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.
Sourcepub fn holds(&self, doc: &Doc) -> bool
pub fn holds(&self, doc: &Doc) -> bool
Whether doc holds a resource of this kind: its own read accepts
it.
Sourcepub fn holds_or_older(&self, doc: &Doc) -> bool
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.
Sourcepub fn name(&self, state: &dyn Any) -> String
pub fn name(&self, state: &dyn Any) -> String
What the open resource is called, from a state Self::read
returned.
Sourcepub fn publish(&self, id: &str, doc: &Doc) -> Result<ResourceSpec, ModelError>
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.
Sourcepub fn child(
&self,
doc: &Doc,
id: &str,
) -> Result<Option<ResourceSpec>, ModelError>
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.
Sourcepub fn content(
&self,
doc: &Doc,
item: Option<&str>,
) -> Result<Value, ModelError>
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.
Sourcepub fn reads_item(&self, item: &str) -> bool
pub fn reads_item(&self, item: &str) -> bool
Whether Self::content answers with item: the record publishes a
read of that part.
Sourcepub fn opens_as_item(&self, id: &str) -> bool
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).
Sourcepub fn publish_state(
&self,
id: &str,
state: &dyn Any,
) -> Result<ResourceSpec, ModelError>
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.
Sourcepub fn to_json(&self, state: &dyn Any) -> Result<Value, ModelError>
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.
Sourcepub fn search(&self, doc: &Doc) -> Result<Vec<SearchEntry>, ModelError>
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.
Sourcepub fn register(&self, registry: &mut ActionRegistry)
pub fn register(&self, registry: &mut ActionRegistry)
Register what a replica of this kind replays: the resource’s actions and groups of them.
Sourcepub fn initialize(&self, doc: &mut Doc) -> Result<(), ModelError>
pub fn initialize(&self, doc: &mut Doc) -> Result<(), ModelError>
Write a brand-new record’s genesis (Resource::initialize).
Sourcepub fn rewrite(&self, doc: &mut Doc, from: u32) -> Result<(), ModelError>
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.
Sourcepub fn needs_migrate(&self, doc: &Doc) -> bool
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.
Trait Implementations§
Source§impl Clone for ResourceKind
impl Clone for ResourceKind
impl Copy for ResourceKind
Auto Trait Implementations§
impl Forget for ResourceKind
impl Freeze for ResourceKind
impl Move for ResourceKind
impl RefUnwindSafe for ResourceKind
impl Send for ResourceKind
impl Sync for ResourceKind
impl Unpin for ResourceKind
impl UnsafeUnpin for ResourceKind
impl UnwindSafe for ResourceKind
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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