pub struct ReentrantCustomCollectionView<C, I, W> { /* private fields */ }
Expand description
A view that supports accessing a collection of views of the same kind, indexed by an ordered key, possibly several subviews at a time.
Implementations§
source§impl<C, I, W> ReentrantCustomCollectionView<C, I, W>
impl<C, I, W> ReentrantCustomCollectionView<C, I, W>
sourcepub async fn try_load_entry_mut<Q>(
&mut self,
index: &Q,
) -> Result<WriteGuardedView<W>, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
pub async fn try_load_entry_mut<Q>(
&mut self,
index: &Q,
) -> Result<WriteGuardedView<W>, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
Loads a subview for the data at the given index in the collection. If an entry is absent then a default entry is put in the collection on this index.
let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> =
ReentrantCustomCollectionView::load(context).await.unwrap();
let subview = view.try_load_entry_mut(&23).await.unwrap();
let value = subview.get();
assert_eq!(*value, String::default());
sourcepub async fn try_load_entry<Q>(
&self,
index: &Q,
) -> Result<Option<ReadGuardedView<W>>, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
pub async fn try_load_entry<Q>(
&self,
index: &Q,
) -> Result<Option<ReadGuardedView<W>>, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
Loads a subview at the given index in the collection and gives read-only access to the data.
If an entry is absent then None
is returned.
let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> =
ReentrantCustomCollectionView::load(context).await.unwrap();
{
let _subview = view.try_load_entry_mut(&23).await.unwrap();
}
let subview = view.try_load_entry(&23).await.unwrap().unwrap();
let value = subview.get();
assert_eq!(*value, String::default());
sourcepub async fn contains_key<Q>(&self, index: &Q) -> Result<bool, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
pub async fn contains_key<Q>(&self, index: &Q) -> Result<bool, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
Returns true
if the collection contains a value for the specified key.
let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> =
ReentrantCustomCollectionView::load(context).await.unwrap();
let _subview = view.try_load_entry_mut(&23).await.unwrap();
assert!(view.contains_key(&23).await.unwrap());
assert!(!view.contains_key(&24).await.unwrap());
sourcepub fn remove_entry<Q>(&mut self, index: &Q) -> Result<(), ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
pub fn remove_entry<Q>(&mut self, index: &Q) -> Result<(), ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
Removes an entry. If absent then nothing happens.
let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> =
ReentrantCustomCollectionView::load(context).await.unwrap();
let mut subview = view.try_load_entry_mut(&23).await.unwrap();
let value = subview.get_mut();
assert_eq!(*value, String::default());
view.remove_entry(&23);
let keys = view.indices().await.unwrap();
assert_eq!(keys.len(), 0);
sourcepub fn try_reset_entry_to_default<Q>(
&mut self,
index: &Q,
) -> Result<(), ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
pub fn try_reset_entry_to_default<Q>(
&mut self,
index: &Q,
) -> Result<(), ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
Marks the entry so that it is removed in the next flush.
let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> =
ReentrantCustomCollectionView::load(context).await.unwrap();
{
let mut subview = view.try_load_entry_mut(&23).await.unwrap();
let value = subview.get_mut();
*value = String::from("Hello");
}
{
view.try_reset_entry_to_default(&23).unwrap();
let subview = view.try_load_entry(&23).await.unwrap().unwrap();
let value = subview.get();
assert_eq!(*value, String::default());
}
source§impl<C, I, W> ReentrantCustomCollectionView<C, I, W>
impl<C, I, W> ReentrantCustomCollectionView<C, I, W>
sourcepub async fn try_load_entries_mut<Q>(
&mut self,
indices: impl IntoIterator<Item = Q>,
) -> Result<Vec<WriteGuardedView<W>>, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
pub async fn try_load_entries_mut<Q>(
&mut self,
indices: impl IntoIterator<Item = Q>,
) -> Result<Vec<WriteGuardedView<W>>, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
Load multiple entries for writing at once. The entries in indices have to be all distinct.
let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> =
ReentrantCustomCollectionView::load(context).await.unwrap();
let indices = vec![23, 42];
let subviews = view.try_load_entries_mut(indices).await.unwrap();
let value1 = subviews[0].get();
let value2 = subviews[1].get();
assert_eq!(*value1, String::default());
assert_eq!(*value2, String::default());
sourcepub async fn try_load_entries<Q>(
&self,
indices: impl IntoIterator<Item = Q>,
) -> Result<Vec<Option<ReadGuardedView<W>>>, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
pub async fn try_load_entries<Q>(
&self,
indices: impl IntoIterator<Item = Q>,
) -> Result<Vec<Option<ReadGuardedView<W>>>, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
Load multiple entries for reading at once. The entries in indices have to be all distinct.
let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> =
ReentrantCustomCollectionView::load(context).await.unwrap();
{
let _subview = view.try_load_entry_mut(&23).await.unwrap();
}
let indices = vec![23, 42];
let subviews = view.try_load_entries(indices).await.unwrap();
assert!(subviews[1].is_none());
let value0 = subviews[0].as_ref().unwrap().get();
assert_eq!(*value0, String::default());
sourcepub async fn try_load_all_entries_mut<Q>(
&mut self,
) -> Result<Vec<(I, WriteGuardedView<W>)>, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
pub async fn try_load_all_entries_mut<Q>(
&mut self,
) -> Result<Vec<(I, WriteGuardedView<W>)>, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
Loads all entries for writing at once. The entries in indices have to be all distinct.
let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> =
ReentrantCustomCollectionView::load(context).await.unwrap();
{
let _subview = view.try_load_entry_mut(&23).await.unwrap();
}
let subviews = view.try_load_all_entries_mut().await.unwrap();
assert_eq!(subviews.len(), 1);
sourcepub async fn try_load_all_entries<Q>(
&self,
) -> Result<Vec<(I, ReadGuardedView<W>)>, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
pub async fn try_load_all_entries<Q>(
&self,
) -> Result<Vec<(I, ReadGuardedView<W>)>, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
Load multiple entries for reading at once. The entries in indices have to be all distinct.
let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> =
ReentrantCustomCollectionView::load(context).await.unwrap();
{
let _subview = view.try_load_entry_mut(&23).await.unwrap();
}
let subviews = view.try_load_all_entries().await.unwrap();
assert_eq!(subviews.len(), 1);
source§impl<C, I, W> ReentrantCustomCollectionView<C, I, W>
impl<C, I, W> ReentrantCustomCollectionView<C, I, W>
sourcepub async fn indices(&self) -> Result<Vec<I>, ViewError>
pub async fn indices(&self) -> Result<Vec<I>, ViewError>
Returns the list of indices in the collection. The order is determined by the custom serialization.
let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> =
ReentrantCustomCollectionView::load(context).await.unwrap();
view.try_load_entry_mut(&23).await.unwrap();
view.try_load_entry_mut(&25).await.unwrap();
let indices = view.indices().await.unwrap();
assert_eq!(indices, vec![23, 25]);
sourcepub async fn count(&self) -> Result<usize, ViewError>
pub async fn count(&self) -> Result<usize, ViewError>
Returns the number of entries in the collection.
let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> =
ReentrantCustomCollectionView::load(context).await.unwrap();
view.try_load_entry_mut(&23).await.unwrap();
view.try_load_entry_mut(&25).await.unwrap();
assert_eq!(view.count().await.unwrap(), 2);
sourcepub async fn for_each_index_while<F>(&self, f: F) -> Result<(), ViewError>
pub async fn for_each_index_while<F>(&self, f: F) -> Result<(), ViewError>
Applies a function f on each index. Indices are visited in an order determined by the custom serialization. If the function f returns false then the loop ends prematurely.
let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> =
ReentrantCustomCollectionView::load(context).await.unwrap();
view.try_load_entry_mut(&28).await.unwrap();
view.try_load_entry_mut(&24).await.unwrap();
view.try_load_entry_mut(&23).await.unwrap();
let mut part_indices = Vec::new();
view.for_each_index_while(|index| {
part_indices.push(index);
Ok(part_indices.len() < 2)
})
.await
.unwrap();
assert_eq!(part_indices, vec![23, 24]);
sourcepub async fn for_each_index<F>(&self, f: F) -> Result<(), ViewError>
pub async fn for_each_index<F>(&self, f: F) -> Result<(), ViewError>
Applies a function f on each index. Indices are visited in an order determined by the custom serialization.
let mut view: ReentrantCustomCollectionView<_, u128, RegisterView<_, String>> =
ReentrantCustomCollectionView::load(context).await.unwrap();
view.try_load_entry_mut(&28).await.unwrap();
view.try_load_entry_mut(&24).await.unwrap();
view.try_load_entry_mut(&23).await.unwrap();
let mut indices = Vec::new();
view.for_each_index(|index| {
indices.push(index);
Ok(())
})
.await
.unwrap();
assert_eq!(indices, vec![23, 24, 28]);
Trait Implementations§
source§impl<C, I, W> ClonableView<C> for ReentrantCustomCollectionView<C, I, W>
impl<C, I, W> ClonableView<C> for ReentrantCustomCollectionView<C, I, W>
source§fn clone_unchecked(&mut self) -> Result<Self, ViewError>
fn clone_unchecked(&mut self) -> Result<Self, ViewError>
source§impl<C, K, V> ContainerType for ReentrantCustomCollectionView<C, K, V>where
C: Send + Sync + Context,
K: InputType + OutputType + CustomSerialize + Debug + Clone,
V: View<C> + OutputType,
MapInput<K>: InputType,
MapFilters<K>: InputType,
impl<C, K, V> ContainerType for ReentrantCustomCollectionView<C, K, V>where
C: Send + Sync + Context,
K: InputType + OutputType + CustomSerialize + Debug + Clone,
V: View<C> + OutputType,
MapInput<K>: InputType,
MapFilters<K>: InputType,
source§async fn resolve_field(&self, ctx: &Context<'_>) -> ServerResult<Option<Value>>
async fn resolve_field(&self, ctx: &Context<'_>) -> ServerResult<Option<Value>>
async_graphql::Value
. Read moresource§async fn find_entity(
&self,
ctx: &Context<'_>,
params: &Value,
) -> ServerResult<Option<Value>>
async fn find_entity( &self, ctx: &Context<'_>, params: &Value, ) -> ServerResult<Option<Value>>
source§fn collect_all_fields<'a>(
&'a self,
ctx: &ContextBase<'a, &'a Positioned<SelectionSet>>,
fields: &mut Fields<'a>,
) -> Result<(), ServerError>
fn collect_all_fields<'a>( &'a self, ctx: &ContextBase<'a, &'a Positioned<SelectionSet>>, fields: &mut Fields<'a>, ) -> Result<(), ServerError>
source§impl<C, I, W> HashableView<C> for ReentrantCustomCollectionView<C, I, W>
impl<C, I, W> HashableView<C> for ReentrantCustomCollectionView<C, I, W>
§type Hasher = CoreWrapper<Sha3_256Core>
type Hasher = CoreWrapper<Sha3_256Core>
source§impl<C, K, V> OutputType for ReentrantCustomCollectionView<C, K, V>where
C: Send + Sync + Context,
K: InputType + OutputType + CustomSerialize + Debug + Clone,
V: View<C> + OutputType,
MapInput<K>: InputType,
MapFilters<K>: InputType,
impl<C, K, V> OutputType for ReentrantCustomCollectionView<C, K, V>where
C: Send + Sync + Context,
K: InputType + OutputType + CustomSerialize + Debug + Clone,
V: View<C> + OutputType,
MapInput<K>: InputType,
MapFilters<K>: InputType,
source§fn create_type_info(registry: &mut Registry) -> String
fn create_type_info(registry: &mut Registry) -> String
source§async fn resolve(
&self,
ctx: &ContextSelectionSet<'_>,
_field: &Positioned<Field>,
) -> ServerResult<Value>
async fn resolve( &self, ctx: &ContextSelectionSet<'_>, _field: &Positioned<Field>, ) -> ServerResult<Value>
async_graphql::Value
.source§fn qualified_type_name() -> String
fn qualified_type_name() -> String
source§impl<C: Send + Sync, K: OutputType, V: OutputType> TypeName for ReentrantCustomCollectionView<C, K, V>
impl<C: Send + Sync, K: OutputType, V: OutputType> TypeName for ReentrantCustomCollectionView<C, K, V>
source§impl<C, I, W> View<C> for ReentrantCustomCollectionView<C, I, W>
impl<C, I, W> View<C> for ReentrantCustomCollectionView<C, I, W>
source§const NUM_INIT_KEYS: usize = 0usize
const NUM_INIT_KEYS: usize = 0usize
source§fn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>
fn pre_load(context: &C) -> Result<Vec<Vec<u8>>, ViewError>
source§fn post_load(context: C, values: &[Option<Vec<u8>>]) -> Result<Self, ViewError>
fn post_load(context: C, values: &[Option<Vec<u8>>]) -> Result<Self, ViewError>
source§fn load<'async_trait>(
context: C,
) -> Pin<Box<dyn Future<Output = Result<Self, ViewError>> + Send + 'async_trait>>where
Self: 'async_trait,
fn load<'async_trait>(
context: C,
) -> Pin<Box<dyn Future<Output = Result<Self, ViewError>> + Send + 'async_trait>>where
Self: 'async_trait,
source§fn rollback(&mut self)
fn rollback(&mut self)
flush
should have no effect to storage.source§fn has_pending_changes<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn has_pending_changes<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
true
if flushing this view would result in changes to the persistent storage.source§fn flush(&mut self, batch: &mut Batch) -> Result<bool, ViewError>
fn flush(&mut self, batch: &mut Batch) -> Result<bool, ViewError>
batch
variable first. If the view is dropped without calling flush
, staged
changes are simply lost.
The returned boolean indicates whether the operation removes the view or not.impl<C, K, V> ObjectType for ReentrantCustomCollectionView<C, K, V>where
C: Send + Sync + Context,
K: InputType + OutputType + CustomSerialize + Debug + Clone,
V: View<C> + OutputType,
MapInput<K>: InputType,
MapFilters<K>: InputType,
Auto Trait Implementations§
impl<C, I, W> !Freeze for ReentrantCustomCollectionView<C, I, W>
impl<C, I, W> !RefUnwindSafe for ReentrantCustomCollectionView<C, I, W>
impl<C, I, W> Send for ReentrantCustomCollectionView<C, I, W>
impl<C, I, W> Sync for ReentrantCustomCollectionView<C, I, W>
impl<C, I, W> Unpin for ReentrantCustomCollectionView<C, I, W>
impl<C, I, W> !UnwindSafe for ReentrantCustomCollectionView<C, I, W>
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
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 moresource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
source§impl<T> MockResults for T
impl<T> MockResults for T
§type Results = T
type Results = T
MockInstance
.source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
impl<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
source§fn read<'instance>(
&self,
instance: &'instance &mut I,
location: GuestPointer,
length: u32,
) -> Result<Cow<'instance, [u8]>, RuntimeError>
fn read<'instance>( &self, instance: &'instance &mut I, location: GuestPointer, length: u32, ) -> Result<Cow<'instance, [u8]>, RuntimeError>
Reads length
bytes from memory from the provided location
.
source§fn write(
&mut self,
instance: &mut &mut I,
location: GuestPointer,
bytes: &[u8],
) -> Result<(), RuntimeError>
fn write( &mut self, instance: &mut &mut I, location: GuestPointer, bytes: &[u8], ) -> Result<(), RuntimeError>
Writes the bytes
to memory at the provided location
.