pub struct CustomSetView<C, I> { /* private fields */ }Expand description
A View implementing the set functionality with the index I being a type with a custom
serialization format.
Implementations§
Source§impl<C: Context, I: CustomSerialize> CustomSetView<C, I>
impl<C: Context, I: CustomSerialize> CustomSetView<C, I>
Sourcepub fn insert<Q>(&mut self, index: &Q) -> Result<(), ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
pub fn insert<Q>(&mut self, index: &Q) -> Result<(), ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
Inserts a value. If present then it has no effect.
let mut set = CustomSetView::<_, u128>::load(context).await.unwrap();
set.insert(&(34 as u128));
assert_eq!(set.indices().await.unwrap().len(), 1);Sourcepub fn remove<Q>(&mut self, index: &Q) -> Result<(), ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
pub fn remove<Q>(&mut self, index: &Q) -> Result<(), ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
Removes a value. If absent then nothing is done.
let mut set = CustomSetView::<_, u128>::load(context).await.unwrap();
set.remove(&(34 as u128));
assert_eq!(set.indices().await.unwrap().len(), 0);Source§impl<C, I> CustomSetView<C, I>where
C: Context,
I: CustomSerialize,
impl<C, I> CustomSetView<C, I>where
C: Context,
I: CustomSerialize,
Sourcepub async fn contains<Q>(&self, index: &Q) -> Result<bool, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
pub async fn contains<Q>(&self, index: &Q) -> Result<bool, ViewError>where
I: Borrow<Q>,
Q: CustomSerialize,
Returns true if the given index exists in the set.
let mut set = CustomSetView::<_, u128>::load(context).await.unwrap();
set.insert(&(34 as u128));
assert_eq!(set.contains(&(34 as u128)).await.unwrap(), true);
assert_eq!(set.contains(&(37 as u128)).await.unwrap(), false);Source§impl<C, I> CustomSetView<C, I>
impl<C, I> CustomSetView<C, I>
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 set. The order is determined by the custom serialization.
let mut set = CustomSetView::<_, u128>::load(context).await.unwrap();
set.insert(&(34 as u128));
set.insert(&(37 as u128));
assert_eq!(set.indices().await.unwrap(), vec![34 as u128, 37 as u128]);Sourcepub async fn count(&self) -> Result<usize, ViewError>
pub async fn count(&self) -> Result<usize, ViewError>
Returns the number of entries of the set.
let mut set = CustomSetView::<_, u128>::load(context).await.unwrap();
set.insert(&(34 as u128));
set.insert(&(37 as u128));
assert_eq!(set.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 does return false, then the loop prematurely ends.
let mut set = CustomSetView::<_, u128>::load(context).await.unwrap();
set.insert(&(34 as u128));
set.insert(&(37 as u128));
set.insert(&(42 as u128));
let mut count = 0;
set.for_each_index_while(|_key| {
count += 1;
Ok(count < 5)
})
.await
.unwrap();
assert_eq!(count, 3);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 set = CustomSetView::<_, u128>::load(context).await.unwrap();
set.insert(&(34 as u128));
set.insert(&(37 as u128));
set.insert(&(42 as u128));
let mut count = 0;
set.for_each_index(|_key| {
count += 1;
Ok(())
})
.await
.unwrap();
assert_eq!(count, 3);Trait Implementations§
Source§impl<C, I> Allocative for CustomSetView<C, I>
impl<C, I> Allocative for CustomSetView<C, I>
Source§impl<C, I> ClonableView for CustomSetView<C, I>
impl<C, I> ClonableView for CustomSetView<C, I>
Source§fn clone_unchecked(&mut self) -> Result<Self, ViewError>
fn clone_unchecked(&mut self) -> Result<Self, ViewError>
Source§impl<C, I> ContainerType for CustomSetView<C, I>
impl<C, I> ContainerType for CustomSetView<C, I>
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: Context, I> HashableView for CustomSetView<C, I>where
Self: View,
impl<C: Context, I> HashableView for CustomSetView<C, I>where
Self: View,
Source§impl<C, I> OutputType for CustomSetView<C, I>
impl<C, I> OutputType for CustomSetView<C, I>
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, I: OutputType> TypeName for CustomSetView<C, I>
impl<C: Send + Sync, I: OutputType> TypeName for CustomSetView<C, I>
Source§impl<C, I> View for CustomSetView<C, I>
impl<C, I> View for CustomSetView<C, I>
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 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 pre_save(&self, batch: &mut Batch) -> Result<bool, ViewError>
fn pre_save(&self, batch: &mut Batch) -> Result<bool, ViewError>
batch variable.
The returned boolean indicates whether the operation removes the view or not.Source§fn post_save(&mut self)
fn post_save(&mut self)
pre_save and after the batch has been successfully written to storage.
This leaves the view in a clean state with no pending changes. Read moreSource§fn clear(&mut self)
fn clear(&mut self)
impl<C, I> ObjectType for CustomSetView<C, I>
Auto Trait Implementations§
impl<C, I> Freeze for CustomSetView<C, I>where
C: Freeze,
impl<C, I> RefUnwindSafe for CustomSetView<C, I>where
C: RefUnwindSafe,
I: RefUnwindSafe,
impl<C, I> Send for CustomSetView<C, I>
impl<C, I> Sync for CustomSetView<C, I>
impl<C, I> Unpin for CustomSetView<C, I>
impl<C, I> UnwindSafe for CustomSetView<C, I>where
C: UnwindSafe,
I: UnwindSafe,
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> 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
Source§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.