Struct Collection
pub struct Collection<T> { /* private fields */ }Expand description
An ordered collection of items addressed by Id.
Stored as a map from id to { k: order key, v: value }. Editing an item
writes only that item; a move rewrites one order key; concurrent inserts
from several collaborators interleave deterministically; deleting an item
never disturbs another item’s identity. This is the default container for
anything a user adds, reorders or removes.
A collection read from a document remembers each item’s order key, so a
later change re-reads only the items it touched
(Model::refresh) instead of the whole collection.
Cloning a collection shares its items: a clone copies one pointer per item, and an item is copied only when one of the collections sharing it changes it. A view holding the state it was shown therefore costs the next change one copied item, not a copy of every item.
Implementations§
§impl<T> Collection<T>
impl<T> Collection<T>
pub fn new() -> Collection<T>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn membership(&self) -> Membership
pub fn membership(&self) -> Membership
Which ids the collection holds, in which order ([Membership]).
Editing an item keeps it; adding, removing or moving one changes it.
pub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Items in collection order.
pub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn values(&self) -> Values<'_, T>
pub fn ids(&self) -> Ids<'_, T>
pub fn contains(&self, id: &Id) -> bool
pub fn position(&self, id: &Id) -> Option<usize>
pub fn get(&self, id: &Id) -> Option<&T>
pub fn get_mut(&mut self, id: &Id) -> Option<&mut T>
pub fn get_mut(&mut self, id: &Id) -> Option<&mut T>
The item id, to change. Copies it first when a clone of this
collection still shares it; no other item is copied.
pub fn quarantined(&self) -> &[Quarantined]
pub fn quarantined(&self) -> &[Quarantined]
The stored items that did not read, each with why: the view shows
the rest, and these are repaired by pushing a whole item under the
id or removed ([Quarantined]).
pub fn discard(&mut self, id: &Id) -> bool
pub fn discard(&mut self, id: &Id) -> bool
Forget the quarantined item id: the next write deletes it from the
document, as it deletes any item no longer in the collection.
Whether it was quarantined.
pub fn push(&mut self, id: Id, item: T) -> Id
pub fn push(&mut self, id: Id, item: T) -> Id
Append an item. Returns its id for chaining. An id already present is replaced in place; a quarantined one is repaired by it.
pub fn insert(&mut self, index: usize, id: Id, item: T) -> Id
pub fn insert(&mut self, index: usize, id: Id, item: T) -> Id
Insert an item at index (clamped to the end). An id already present
is moved there.
pub fn remove(&mut self, id: &Id) -> Option<T>
pub fn move_to(&mut self, id: &Id, index: usize) -> bool
pub fn move_to(&mut self, id: &Id, index: usize) -> bool
Move an item to index (clamped to the end). Returns whether it exists.
pub fn retain(&mut self, keep: impl FnMut(&Id, &T) -> bool)
pub fn sort_by(&mut self, compare: impl FnMut(&T, &T) -> Ordering)
Trait Implementations§
§impl ChildList for Collection<ChildRef>
impl ChildList for Collection<ChildRef>
§impl<T> Clone for Collection<T>where
T: Clone,
impl<T> Clone for Collection<T>where
T: Clone,
§fn clone(&self) -> Collection<T>
fn clone(&self) -> Collection<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl<T> Debug for Collection<T>where
T: Debug,
impl<T> Debug for Collection<T>where
T: Debug,
§impl<T> Default for Collection<T>
impl<T> Default for Collection<T>
§fn default() -> Collection<T>
fn default() -> Collection<T>
§impl<T> FromIterator<(Id, T)> for Collection<T>
impl<T> FromIterator<(Id, T)> for Collection<T>
§fn from_iter<I>(iter: I) -> Collection<T>where
I: IntoIterator<Item = (Id, T)>,
fn from_iter<I>(iter: I) -> Collection<T>where
I: IntoIterator<Item = (Id, T)>,
§impl<T> Index<&Id> for Collection<T>
impl<T> Index<&Id> for Collection<T>
§impl<T> ItemSource for Collection<T>where
T: Model,
impl<T> ItemSource for Collection<T>where
T: Model,
§fn item_collection(&self, field: &'static str) -> ItemCollection
fn item_collection(&self, field: &'static str) -> ItemCollection
§fn item_presence(&self) -> usize
fn item_presence(&self) -> usize
§fn label_of_item(&self, id: &Id) -> Option<String>
fn label_of_item(&self, id: &Id) -> Option<String>
id, when there is one.§fn item_texts(&self, field: &'static str, found: &mut Vec<ItemText>)
fn item_texts(&self, field: &'static str, found: &mut Vec<ItemText>)
§fn nested_items(&self, field: &'static str, out: &mut Vec<ItemCollection>)
fn nested_items(&self, field: &'static str, out: &mut Vec<ItemCollection>)
§impl<T> Model for Collection<T>where
T: Model,
impl<T> Model for Collection<T>where
T: Model,
§const SHAPE: Shape
const SHAPE: Shape
Shape.
Types written whole keep the default.§const CHECKS: bool = T::CHECKS
const CHECKS: bool = T::CHECKS
#[model(check)]
invariant; Self::check has nothing to do otherwise.§const OPS: bool = T::OPS
const OPS: bool = T::OPS
Operations, rich text’s): a record routes
those edits’ gestures, landing places and schemas only into such
fields, and never instantiates the routing for the others.§const TABLE: &'static ModelTable
const TABLE: &'static ModelTable
crate::table]): by default its own functions, erased.§type Paths<R> = Path<R, Collection<T>>
type Paths<R> = Path<R, Collection<T>>
R:
a struct of field paths for a record, the Path itself for a value
edited whole or through its own operations.§fn value_schema() -> Value
fn value_schema() -> Value
Self::to_json), as
the published field edit describes what a path takes; the default
accepts any value.§fn field_type(types: &mut TypeSet) -> FieldType
fn field_type(types: &mut TypeSet) -> FieldType
FieldType), declaring the records
and enums it names in types. The default describes no type: any
value.§fn paths_at<R>(path: Path<R, Collection<T>>) -> Path<R, Collection<T>>
fn paths_at<R>(path: Path<R, Collection<T>>) -> Path<R, Collection<T>>
path.§fn op_coalesces(
path: &[Segment],
previous: &Value,
next: &Value,
) -> Option<bool>
fn op_coalesces( path: &[Segment], previous: &Value, next: &Value, ) -> Option<bool>
path below
this type are one gesture (Operations); None
when nothing there has one.§fn op_continuable(path: &[Segment], op: &Value) -> Option<bool>
fn op_continuable(path: &[Segment], op: &Value) -> Option<bool>
op at path.§fn op_describe(path: &[Segment], op: &Value) -> Option<OpDescription>
fn op_describe(path: &[Segment], op: &Value) -> Option<OpDescription>
§fn op_lands(&self, path: &[Segment], op: &Value) -> Option<Place>
fn op_lands(&self, path: &[Segment], op: &Value) -> Option<Place>
op at path below this value is after
it applied.§fn op_schemas(prefix: &str, out: &mut Vec<(String, Value)>)
fn op_schemas(prefix: &str, out: &mut Vec<(String, Value)>)
prefix (* for every item).§fn from_json(value: &Value) -> Result<Collection<T>, ModelError>
fn from_json(value: &Value) -> Result<Collection<T>, ModelError>
Self::to_json form. Read more§fn edit(
doc: &mut AutoCommit,
slot: Slot<'_>,
path: &[Segment],
op: &EditOp,
cx: &mut ActionCx,
) -> Result<(), ModelError>
fn edit( doc: &mut AutoCommit, slot: Slot<'_>, path: &[Segment], op: &EditOp, cx: &mut ActionCx, ) -> Result<(), ModelError>
op at path, below the value in slot,
touching only what it changes, then run the invariants of the values
it touched. The default edits a value only as a whole.§fn check(&self) -> Result<(), Refusal>
fn check(&self) -> Result<(), Refusal>
#[model(check)] invariant of this value and the values
inside it.§fn get_at(&self, path: &[Segment]) -> Option<&(dyn Any + 'static)>
fn get_at(&self, path: &[Segment]) -> Option<&(dyn Any + 'static)>
path below this one, if it is there. A value with
nothing inside it is found only at the empty path.§fn diff<R>(
&self,
after: &Collection<T>,
path: &[Segment],
out: &mut Vec<Edit<R>>,
)
fn diff<R>( &self, after: &Collection<T>, path: &[Segment], out: &mut Vec<Edit<R>>, )
self into after, at path below the
record: what a surface that edited a local copy submits. The default
sets the value whole when it changed; containers and records edit
only what differs, item by item and field by field. A value that
would store as it is (Self::stores_as) is compared in memory,
without turning either side into JSON.§fn load(
doc: &AutoCommit,
value: &Value<'_>,
id: &ExId,
) -> Result<Collection<T>, ModelError>
fn load( doc: &AutoCommit, value: &Value<'_>, id: &ExId, ) -> Result<Collection<T>, ModelError>
§fn store(&self, doc: &mut AutoCommit, slot: Slot<'_>) -> Result<(), ModelError>
fn store(&self, doc: &mut AutoCommit, slot: Slot<'_>) -> Result<(), ModelError>
self into slot, changing only what differs from what the slot
already holds.§fn stores_as(&self, before: &Collection<T>) -> bool
fn stores_as(&self, before: &Collection<T>) -> bool
self over a slot that holds before, as a
store left it, would change nothing: an in-memory
comparison, so an action that changed one item of a long collection
does not visit the others. Must only answer true when store would
write no operation; the default answers false (unknown).§fn store_changed(
&self,
before: &Collection<T>,
doc: &mut AutoCommit,
slot: Slot<'_>,
dirty: &Delta,
) -> Result<(), ModelError>
fn store_changed( &self, before: &Collection<T>, doc: &mut AutoCommit, slot: Slot<'_>, dirty: &Delta, ) -> Result<(), ModelError>
§fn refresh(
&mut self,
doc: &AutoCommit,
value: &Value<'_>,
id: &ExId,
delta: &Delta,
) -> Result<(), ModelError>
fn refresh( &mut self, doc: &AutoCommit, value: &Value<'_>, id: &ExId, delta: &Delta, ) -> Result<(), ModelError>
delta,
re-reading only what they touched. value and id are what the
parent’s slot holds now — the same object as when self was read, or
the parent would have read it anew. The default reads the value again,
which is right for scalars and short values. Read more§fn collect_text(&self, out: &mut Vec<String>)
fn collect_text(&self, out: &mut Vec<String>)
§fn missing() -> Result<Collection<T>, ModelError>
fn missing() -> Result<Collection<T>, ModelError>
§const NULLABLE: bool = false
const NULLABLE: bool = false
null is a value of the type: an absent Option. A field
edit setting any other type to null is refused.§fn nested_collections(&self) -> Vec<ItemCollection>
fn nested_collections(&self) -> Vec<ItemCollection>
#[derive(Model)] lists a
record’s, the default has none.§fn read_whole(&mut self, doc: &AutoCommit) -> Result<(), ModelError>
fn read_whole(&mut self, doc: &AutoCommit) -> Result<(), ModelError>
#[model(whole)]: a value read lazily (rich text reads its
paragraphs as views ask for them) reads all of it, so every reader of
the record — a verb, search, read_content — sees all of it. The
default has nothing more to read. Read more§impl<T> PartialEq for Collection<T>where
T: PartialEq,
impl<T> PartialEq for Collection<T>where
T: PartialEq,
§fn eq(&self, other: &Collection<T>) -> bool
fn eq(&self, other: &Collection<T>) -> bool
Equal items in equal order; where each item’s order key came from is bookkeeping, not content. An item two clones still share is the same value and is not compared field by field.
§impl<T> PublishedItems for Collection<T>where
T: Model,
impl<T> PublishedItems for Collection<T>where
T: Model,
const ITEM_TABLE: &'static ModelTable = T::TABLE
Auto Trait Implementations§
impl<T> !Freeze for Collection<T>
impl<T> RefUnwindSafe for Collection<T>where
T: RefUnwindSafe,
impl<T> Send for Collection<T>
impl<T> Sync for Collection<T>
impl<T> Unpin for Collection<T>
impl<T> UnsafeUnpin for Collection<T>
impl<T> UnwindSafe for Collection<T>where
T: RefUnwindSafe,
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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