Struct linera_views::views::set_view::CustomSetView
source · 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, I> CustomSetView<C, I>
impl<C, I> 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>
impl<C, I> CustomSetView<C, I>
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> ClonableView<C> for CustomSetView<C, I>
impl<C, I> ClonableView<C> 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> HashableView<C> for CustomSetView<C, I>
impl<C, I> HashableView<C> for CustomSetView<C, I>
§type Hasher = CoreWrapper<Sha3_256Core>
type Hasher = CoreWrapper<Sha3_256Core>
source§impl<C, I> OutputType for CustomSetView<C, I>
impl<C, I> OutputType for CustomSetView<C, I>
source§fn qualified_type_name() -> String
fn qualified_type_name() -> String
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§impl<C, I> View<C> for CustomSetView<C, I>
impl<C, I> View<C> 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 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.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
§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
.