Trait matterdb::access::CopyAccessExt [−][src]
Extension trait allowing for easy access to indexes from any type implementing
Access
+ Copy
.
Implementation details
This trait is essentially a thin wrapper around FromAccess
. Where FromAccess
returns
an access error, the methods of this trait will unwrap()
the error and panic.
This trait is helpful for references implementing Access
, such as &Fork
or &dyn Snapshot
because Rust method resolution does not apply AccessExt
to variables of corresponding types.
For example, if fork has type Fork, then fork.get_list("foo")
is not resolved
as AccessExt::get_list(..)
, only (&fork).get_list("foo")
is.
Access
: trait.Access.html
AccessExt
: trait.AccessExt.html
FromAccess
: trait.FromAccess.html
Examples
use matterdb::{access::CopyAccessExt, Database, ListIndex, TemporaryDB}; let db = TemporaryDB::new(); let fork = db.fork(); // Extension methods can be used on `Fork`s: { let mut list: ListIndex<_, String> = fork.get_list("list"); list.push("foo".to_owned()); } // ...and on `Snapshot`s: let snapshot = db.snapshot(); assert!(snapshot .get_map::<_, u64, String>("map") .get(&0) .is_none()); // ...and on `ReadonlyFork`s: { let list = fork.readonly().get_list::<_, String>("list"); assert_eq!(list.len(), 1); } // ...and on `Patch`es: let patch = fork.into_patch(); let list = patch.get_list::<_, String>("list"); assert_eq!(list.len(), 1);
Provided methods
fn get_group<K: ?Sized, I>(self, name: impl Into<String>) -> Group<Self, K, I> where
K: BinaryKey,
I: FromAccess<Self>,
[src]
K: BinaryKey,
I: FromAccess<Self>,
Returns a group of indexes. All indexes in the group have the same type. Indexes are initialized lazily; i.e., no initialization is performed when the group is created.
Note that unlike other methods, this one requires address to be a string. This is to prevent collisions among groups.
fn get_entry<I, V>(self, addr: I) -> Entry<Self::Base, V> where
I: Into<IndexAddress>,
V: BinaryValue,
[src]
I: Into<IndexAddress>,
V: BinaryValue,
fn get_list<I, V>(self, addr: I) -> ListIndex<Self::Base, V> where
I: Into<IndexAddress>,
V: BinaryValue,
[src]
I: Into<IndexAddress>,
V: BinaryValue,
fn get_map<I, K: ?Sized, V>(self, addr: I) -> MapIndex<Self::Base, K, V> where
I: Into<IndexAddress>,
K: BinaryKey,
V: BinaryValue,
[src]
I: Into<IndexAddress>,
K: BinaryKey,
V: BinaryValue,
fn get_sparse_list<I, V>(self, addr: I) -> SparseListIndex<Self::Base, V> where
I: Into<IndexAddress>,
V: BinaryValue,
[src]
I: Into<IndexAddress>,
V: BinaryValue,
Gets a sparse list index with the specified address.
Panics
If the index exists, but is not a sparse list.
fn get_key_set<I, K: ?Sized>(self, addr: I) -> KeySetIndex<Self::Base, K> where
I: Into<IndexAddress>,
K: BinaryKey,
[src]
I: Into<IndexAddress>,
K: BinaryKey,
fn index_type<I>(self, addr: I) -> Option<IndexType> where
I: Into<IndexAddress>,
[src]
I: Into<IndexAddress>,
Gets index type at the specified address, or None
if there is no index.