Skip to main content

Docs

Struct Docs 

Source
pub struct Docs<T> { /* private fields */ }
Expand description

A collection of T.

Cheap to clone and cheap to keep around, the same way crate::Map is: the handle is a pointer and an index, and every clone is the same collection.

Implementations§

Source§

impl<T: Document> Docs<T>

Source

pub fn name(&self) -> Result<String>

The name this collection was opened under.

§Errors

Code::Invalid if called from inside a callback that is already holding this database.

Source

pub fn tag(&self) -> Tag

This collection’s shape tag.

Source

pub fn put(&self, doc: &T) -> Result<bool>

Store a document, replacing whatever was under its id.

Answers whether the id was new. Every index the type declares is brought up to date in the same call, and the old document is taken back out of them first, so an overwrite cannot leave a stale posting behind.

§Errors

Code::Invalid for an id that cannot be a key, and Code::Full for a value at an indexed path that is too long to be one.

Source

pub fn get(&self, id: &<T::Id as Asked>::Ask) -> Result<Option<T>>

Read a document by its id.

§Errors

Code::Corrupt if the stored document is not a T.

Source

pub fn contains(&self, id: &<T::Id as Asked>::Ask) -> Result<bool>

Whether an id is in the collection, without reading the document.

§Errors

Code::Invalid for an id that cannot be a key.

Source

pub fn remove(&self, id: &<T::Id as Asked>::Ask) -> Result<bool>

Take a document out, answering whether it was there.

§Errors

Code::Invalid for an id that cannot be a key.

Source

pub fn len(&self) -> Result<usize>

How many documents there are.

§Errors

Code::Invalid if called from inside a callback that is already holding this database.

Source

pub fn is_empty(&self) -> Result<bool>

Whether the collection is empty.

§Errors

The same as Docs::len.

Source

pub fn all(&self) -> Result<Vec<T>>

Every document, in no particular order.

A walk of the whole collection, which is what it says it is. The indexed calls are the ones with a cost model.

§Errors

Code::Corrupt if any stored document is not a T.

Source

pub fn find<V: Asked>( &self, path: impl Into<Path<T, V>>, value: &V::Ask, ) -> Result<Vec<T>>

Every document whose value at path is value.

One probe of the index and one probe of the primary table per document in the answer, so the cost is the size of the answer rather than the size of the collection.

§Errors

Code::Invalid if the collection has no index on that path, because a query that quietly turns into a scan is the thing this API exists not to do.

Source

pub fn count<V: Asked>( &self, path: impl Into<Path<T, V>>, value: &V::Ask, ) -> Result<usize>

How many documents have value at path, without reading any of them.

The number to sort filters by before intersecting them, and it is a probe rather than a walk.

§Errors

The same as Docs::find.

Source

pub fn range<V: Asked, R: RangeBounds<V::Ask>>( &self, path: Ordered<T, V>, range: R, ) -> Result<Vec<T>>

Every document whose value at path falls in range, smallest first.

The bounds are the ordinary Rust range syntax, so .., a..b, a..=b and ..b all work and mean what they say.

§Errors

Code::Invalid if the collection has no index on that path. An index that answers equality only cannot get here at all, because Ordered is a different type from Path and this takes one of them.

Source

pub fn range_rev<V: Asked, R: RangeBounds<V::Ask>>( &self, path: Ordered<T, V>, range: R, ) -> Result<Vec<T>>

Docs::range backwards, largest value first.

§Errors

The same as Docs::range.

Source

pub fn count_range<V: Asked, R: RangeBounds<V::Ask>>( &self, path: Ordered<T, V>, range: R, ) -> Result<usize>

How many documents fall in range at path, without reading any.

This reads the distinct values in the range rather than the documents, so a range covering a million documents under a hundred values costs a hundred.

§Errors

The same as Docs::range.

Source

pub fn memory_bytes(&self) -> Result<usize>

What this collection is holding, documents and indexes together.

§Errors

Code::Invalid if called from inside a callback that is already holding this database.

Trait Implementations§

Source§

impl<T> Clone for Docs<T>

Source§

fn clone(&self) -> Docs<T>

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<T> Debug for Docs<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Docs<T>

§

impl<T> !Send for Docs<T>

§

impl<T> !Sync for Docs<T>

§

impl<T> !UnwindSafe for Docs<T>

§

impl<T> Freeze for Docs<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> Unpin for Docs<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for Docs<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

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, 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 = !

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.