Struct matterdb::indexes::Group [−][src]
pub struct Group<T, K: ?Sized, I> { /* fields omitted */ }
Group of indexes distinguished by a prefix.
All indexes in the group have the same type. Indexes are initialized lazily; i.e., no initialization is performed when the group is created.
Safety
Using a group within a group (including indirectly via components) can lead to index collision if the keys in both groups have variable length (e.g., keys are strings). A collision in turn may result in logical errors and data corruption. For example:
type StrGroup<T> = Group<T, str, ListIndex<<T as Access>::Base, u64>>; let db = TemporaryDB::new(); let fork = db.fork(); let outer_group: Group<_, str, StrGroup<_>> = FromAccess::from_access(&fork, "group".into()).unwrap(); outer_group.get("foo").get("bar").extend(vec![1, 2]); outer_group.get("foob").get("ar").push(3); // Both accessed lists have the same address and thus share the same data: assert_eq!( fork.get_list(("group", "foobar")).iter().collect::<Vec<u64>>(), vec![1, 2, 3] );
Examples
let db = TemporaryDB::new(); let fork = db.fork(); let group: Group<_, u64, ListIndex<_, u64>> = fork.get_group("group"); group.get(&1).push(1); group.get(&2).extend(vec![1, 2, 3]); // Members of the group can be accessed independently. assert_eq!(fork.get_list::<_, u64>(("group", &2_u64)).len(), 3); // It is possible to enumerate keys in the group, but only if the underlying access // is readonly. let group: Group<_, u64, ListIndex<_, u64>> = fork.readonly().get_group("group"); assert_eq!(group.keys().collect::<Vec<_>>(), vec![1, 2]);
Group keys can be unsized:
let group: Group<_, str, ListIndex<_, u64>> = fork.get_group("unsized_group"); group.get("foo").push(1); group.get("bar").push(42);
Implementations
impl<T, K: ?Sized, I> Group<T, K, I> where
T: Access,
T::Base: AsReadonly<Readonly = T::Base>,
K: BinaryKey,
[src]
impl<T, K: ?Sized, I> Group<T, K, I> where
T: Access,
T::Base: AsReadonly<Readonly = T::Base>,
K: BinaryKey,
[src]pub fn keys(&self) -> GroupKeys<T::Base, K>
[src]
pub fn keys(&self) -> GroupKeys<T::Base, K>
[src]Iterator over keys in this group.
The iterator buffers keys in memory and may become inconsistent. Although
the Rust type system prevents iterating over keys in a group based on Fork
,
it it still possible to make the iterator return inconsistent results. Indeed,
for a group is based on ReadonlyFork
, it is possible to add new indexes via Fork
while the iteration is in progress.
For this reason, it is advised to use this method for groups based on ReadonlyFork
only in the case where stale reads are tolerated or are prevented on the application level.
Groups based on Snapshot
implementations (including Patch
es) are not affected
by this issue.
Trait Implementations
impl<T, K: ?Sized, I> FromAccess<T> for Group<T, K, I> where
T: Access,
K: BinaryKey,
I: FromAccess<T>,
[src]
impl<T, K: ?Sized, I> FromAccess<T> for Group<T, K, I> where
T: Access,
K: BinaryKey,
I: FromAccess<T>,
[src]fn from_access(access: T, addr: IndexAddress) -> Result<Self, AccessError>
[src]
fn from_access(access: T, addr: IndexAddress) -> Result<Self, AccessError>
[src]Constructs the object at the given address. Read more
fn from_root(access: T) -> Result<Self, AccessError>
[src]
fn from_root(access: T) -> Result<Self, AccessError>
[src]Constructs the object from the root of the access
. Read more
Auto Trait Implementations
impl<T, K: ?Sized, I> RefUnwindSafe for Group<T, K, I> where
I: RefUnwindSafe,
K: RefUnwindSafe,
T: RefUnwindSafe,
I: RefUnwindSafe,
K: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, K: ?Sized, I> Send for Group<T, K, I> where
I: Send,
K: Send,
T: Send,
I: Send,
K: Send,
T: Send,
impl<T, K: ?Sized, I> Sync for Group<T, K, I> where
I: Sync,
K: Sync,
T: Sync,
I: Sync,
K: Sync,
T: Sync,
impl<T, K: ?Sized, I> Unpin for Group<T, K, I> where
I: Unpin,
K: Unpin,
T: Unpin,
I: Unpin,
K: Unpin,
T: Unpin,
impl<T, K: ?Sized, I> UnwindSafe for Group<T, K, I> where
I: UnwindSafe,
K: UnwindSafe,
T: UnwindSafe,
I: UnwindSafe,
K: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T