pub struct CustomCollectionView<C, I, W> { /* private fields */ }Expand description
A map view that serializes the indices.
Implementations§
Source§impl<I: CustomSerialize, W: View> CustomCollectionView<W::Context, I, W>
 
impl<I: CustomSerialize, W: View> CustomCollectionView<W::Context, I, W>
Sourcepub async fn load_entry_mut<Q>(
    &mut self,
    index: &Q,
) -> Result<&mut W, ViewError>where
    I: Borrow<Q>,
    Q: CustomSerialize,
 
pub async fn load_entry_mut<Q>(
    &mut self,
    index: &Q,
) -> Result<&mut 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 added to the collection. The resulting view can be modified.
let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> =
    CustomCollectionView::load(context).await.unwrap();
let subview = view.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 for the data at the given index in the collection. If an entry
is absent then None is returned. The resulting view cannot be modified.
May fail if one subview is already being visited.
let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> =
    CustomCollectionView::load(context).await.unwrap();
{
    let _subview = view.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());
}
assert!(view.try_load_entry(&24).await.unwrap().is_none());Sourcepub async fn try_load_entries<'a, Q>(
    &self,
    indices: impl IntoIterator<Item = &'a Q>,
) -> Result<Vec<Option<ReadGuardedView<'_, W>>>, ViewError>where
    I: Borrow<Q>,
    Q: CustomSerialize + 'a,
 
pub async fn try_load_entries<'a, Q>(
    &self,
    indices: impl IntoIterator<Item = &'a Q>,
) -> Result<Vec<Option<ReadGuardedView<'_, W>>>, ViewError>where
    I: Borrow<Q>,
    Q: CustomSerialize + 'a,
Load multiple entries for reading at once. The entries in indices have to be all distinct.
let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> =
    CustomCollectionView::load(context).await.unwrap();
{
    let _subview = view.load_entry_mut(&23).await.unwrap();
}
let subviews = view.try_load_entries(&[23, 42]).await.unwrap();
let value0 = subviews[0].as_ref().unwrap().get();
assert_eq!(*value0, String::default());Sourcepub async fn try_load_entries_pairs<Q>(
    &self,
    indices: impl IntoIterator<Item = Q>,
) -> Result<Vec<(Q, Option<ReadGuardedView<'_, W>>)>, ViewError>
 
pub async fn try_load_entries_pairs<Q>( &self, indices: impl IntoIterator<Item = Q>, ) -> Result<Vec<(Q, Option<ReadGuardedView<'_, W>>)>, ViewError>
Loads multiple entries for reading at once with their keys. The entries in indices have to be all distinct.
let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> =
    CustomCollectionView::load(context).await.unwrap();
{
    let _subview = view.load_entry_mut(&23).await.unwrap();
}
let indices = [23, 42];
let subviews = view.try_load_entries_pairs(indices).await.unwrap();
let value0 = subviews[0].1.as_ref().unwrap().get();
assert_eq!(*value0, String::default());Sourcepub async fn try_load_all_entries(
    &self,
) -> Result<Vec<(I, ReadGuardedView<'_, W>)>, ViewError>where
    I: CustomSerialize,
 
pub async fn try_load_all_entries(
    &self,
) -> Result<Vec<(I, ReadGuardedView<'_, W>)>, ViewError>where
    I: CustomSerialize,
Load all entries for reading at once.
let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> =
    CustomCollectionView::load(context).await.unwrap();
{
    let _subview = view.load_entry_mut(&23).await.unwrap();
}
let subviews = view.try_load_all_entries().await.unwrap();
assert_eq!(subviews.len(), 1);Sourcepub fn reset_entry_to_default<Q>(&mut self, index: &Q) -> Result<(), ViewError>where
    I: Borrow<Q>,
    Q: CustomSerialize,
 
pub fn 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: CustomCollectionView<_, u128, RegisterView<_, String>> =
    CustomCollectionView::load(context).await.unwrap();
let subview = view.load_entry_mut(&23).await.unwrap();
let value = subview.get_mut();
*value = String::from("Hello");
view.reset_entry_to_default(&23).unwrap();
let subview = view.load_entry_mut(&23).await.unwrap();
let value = subview.get_mut();
assert_eq!(*value, String::default());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 from the CollectionView. If absent nothing happens.
let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> =
    CustomCollectionView::load(context).await.unwrap();
let subview = view.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);Source§impl<I: CustomSerialize + Send, W: View> CustomCollectionView<W::Context, I, W>
 
impl<I: CustomSerialize + Send, W: View> CustomCollectionView<W::Context, 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 in the order determined by the custom serialization.
let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> =
    CustomCollectionView::load(context).await.unwrap();
view.load_entry_mut(&23).await.unwrap();
view.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: CollectionView<_, u64, RegisterView<_, String>> =
    CollectionView::load(context).await.unwrap();
view.load_entry_mut(&23).await.unwrap();
view.load_entry_mut(&25).await.unwrap();
assert_eq!(view.count().await.unwrap(), 2);Source§impl<I: CustomSerialize, W: View> CustomCollectionView<W::Context, I, W>
 
impl<I: CustomSerialize, W: View> CustomCollectionView<W::Context, I, W>
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: CustomCollectionView<_, u128, RegisterView<_, String>> =
    CustomCollectionView::load(context).await.unwrap();
view.load_entry_mut(&28).await.unwrap();
view.load_entry_mut(&24).await.unwrap();
view.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 on each index. Indices are visited in an order determined by the custom serialization.
let mut view: CustomCollectionView<_, u128, RegisterView<_, String>> =
    CustomCollectionView::load(context).await.unwrap();
view.load_entry_mut(&28).await.unwrap();
view.load_entry_mut(&24).await.unwrap();
view.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<I: Send + Sync, W: ClonableView> ClonableView for CustomCollectionView<W::Context, I, W>
 
impl<I: Send + Sync, W: ClonableView> ClonableView for CustomCollectionView<W::Context, I, W>
Source§fn clone_unchecked(&mut self) -> Result<Self, ViewError>
 
fn clone_unchecked(&mut self) -> Result<Self, ViewError>
Source§impl<K, V> ContainerType for CustomCollectionView<V::Context, K, V>
 
impl<K, V> ContainerType for CustomCollectionView<V::Context, K, V>
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<I, W: HashableView> HashableView for CustomCollectionView<W::Context, I, W>where
    Self: View,
 
impl<I, W: HashableView> HashableView for CustomCollectionView<W::Context, I, W>where
    Self: View,
Source§impl<K, V> OutputType for CustomCollectionView<V::Context, K, V>
 
impl<K, V> OutputType for CustomCollectionView<V::Context, K, V>
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: InputType, V: OutputType> TypeName for CustomCollectionView<C, K, V>
 
impl<C: Send + Sync, K: InputType, V: OutputType> TypeName for CustomCollectionView<C, K, V>
Source§impl<I: Send + Sync, W: View> View for CustomCollectionView<W::Context, I, W>
 
impl<I: Send + Sync, W: View> View for CustomCollectionView<W::Context, I, W>
Source§const NUM_INIT_KEYS: usize = 0usize
 
const NUM_INIT_KEYS: usize = 0usize
Source§fn pre_load(context: &Self::Context) -> Result<Vec<Vec<u8>>, ViewError>
 
fn pre_load(context: &Self::Context) -> Result<Vec<Vec<u8>>, ViewError>
Source§fn post_load(
    context: Self::Context,
    values: &[Option<Vec<u8>>],
) -> Result<Self, ViewError>
 
fn post_load( context: Self::Context, values: &[Option<Vec<u8>>], ) -> Result<Self, ViewError>
Source§fn rollback(&mut self)
 
fn rollback(&mut self)
flush should have no effect to storage.Source§async fn has_pending_changes(&self) -> bool
 
async fn has_pending_changes(&self) -> bool
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.Source§fn clear(&mut self)
 
fn clear(&mut self)
impl<K, V> ObjectType for CustomCollectionView<V::Context, K, V>
Auto Trait Implementations§
impl<C, I, W> !Freeze for CustomCollectionView<C, I, W>
impl<C, I, W> !RefUnwindSafe for CustomCollectionView<C, I, W>
impl<C, I, W> Send for CustomCollectionView<C, I, W>
impl<C, I, W> Sync for CustomCollectionView<C, I, W>
impl<C, I, W> Unpin for CustomCollectionView<C, I, W>
impl<C, I, W> UnwindSafe for CustomCollectionView<C, I, W>
Blanket Implementations§
Source§impl<T> ArchivePointee for T
 
impl<T> ArchivePointee for T
Source§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> FutureExt for T
 
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
 
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
 
fn with_current_context(self) -> WithContext<Self>
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> IntoRequest<T> for T
 
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
 
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§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
Source§type Results = T
 
type Results = T
MockInstance.Source§impl<T> Pointable for T
 
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
    T: ?Sized,
 
impl<T> PolicyExt for Twhere
    T: ?Sized,
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.