Struct linera_views::views::bucket_queue_view::BucketQueueView
source · pub struct BucketQueueView<C, T, const N: usize> { /* private fields */ }
Expand description
A view that supports a FIFO queue for values of type T
.
The size N
has to be chosen by taking into account the size of the type T
and the basic size of a block. For example a total size of 100 bytes to 10 KB
seems adequate.
Implementations§
source§impl<C, T, const N: usize> BucketQueueView<C, T, N>
impl<C, T, const N: usize> BucketQueueView<C, T, N>
sourcepub fn stored_count(&self) -> usize
pub fn stored_count(&self) -> usize
Gets the number of entries in the container that are stored
let mut queue = BucketQueueView::<_, u8, 5>::load(context).await.unwrap();
queue.push_back(34);
assert_eq!(queue.stored_count(), 0);
source§impl<C, T, const N: usize> BucketQueueView<C, T, N>
impl<C, T, const N: usize> BucketQueueView<C, T, N>
sourcepub fn front(&self) -> Option<&T>
pub fn front(&self) -> Option<&T>
Gets a reference on the front value if any.
let mut queue = BucketQueueView::<_, u8, 5>::load(context).await.unwrap();
queue.push_back(34);
queue.push_back(42);
assert_eq!(queue.front().cloned(), Some(34));
sourcepub fn front_mut(&mut self) -> Option<&mut T>
pub fn front_mut(&mut self) -> Option<&mut T>
Reads the front value, if any.
let mut queue = BucketQueueView::<_, u8, 5>::load(context).await.unwrap();
queue.push_back(34);
queue.push_back(42);
let front = queue.front_mut().unwrap();
*front = 43;
assert_eq!(queue.front().cloned(), Some(43));
sourcepub async fn delete_front(&mut self) -> Result<(), ViewError>
pub async fn delete_front(&mut self) -> Result<(), ViewError>
Deletes the front value, if any.
let mut queue = BucketQueueView::<_, u128, 5>::load(context).await.unwrap();
queue.push_back(34 as u128);
queue.delete_front().await.unwrap();
assert_eq!(queue.elements().await.unwrap(), Vec::<u128>::new());
sourcepub fn push_back(&mut self, value: T)
pub fn push_back(&mut self, value: T)
Pushes a value to the end of the queue.
let mut queue = BucketQueueView::<_, u128, 5>::load(context).await.unwrap();
queue.push_back(34);
assert_eq!(queue.elements().await.unwrap(), vec![34]);
sourcepub async fn elements(&self) -> Result<Vec<T>, ViewError>
pub async fn elements(&self) -> Result<Vec<T>, ViewError>
Returns the list of elements in the queue.
let mut queue = BucketQueueView::<_, u128, 5>::load(context).await.unwrap();
queue.push_back(34);
queue.push_back(37);
assert_eq!(queue.elements().await.unwrap(), vec![34, 37]);
sourcepub async fn back(&mut self) -> Result<Option<T>, ViewError>
pub async fn back(&mut self) -> Result<Option<T>, ViewError>
Returns the last element of a bucket queue view
let mut queue = BucketQueueView::<_, u128, 5>::load(context).await.unwrap();
queue.push_back(34);
queue.push_back(37);
assert_eq!(queue.back().await.unwrap(), Some(37));
sourcepub async fn read_front(&self, count: usize) -> Result<Vec<T>, ViewError>
pub async fn read_front(&self, count: usize) -> Result<Vec<T>, ViewError>
Returns the first elements of a bucket queue view
let mut queue = BucketQueueView::<_, u128, 5>::load(context).await.unwrap();
queue.push_back(34);
queue.push_back(37);
queue.push_back(47);
assert_eq!(queue.read_front(2).await.unwrap(), vec![34, 37]);
sourcepub async fn read_back(&self, count: usize) -> Result<Vec<T>, ViewError>
pub async fn read_back(&self, count: usize) -> Result<Vec<T>, ViewError>
Returns the last element of a bucket queue view
let mut queue = BucketQueueView::<_, u128, 5>::load(context).await.unwrap();
queue.push_back(34);
queue.push_back(37);
queue.push_back(47);
assert_eq!(queue.read_back(2).await.unwrap(), vec![37, 47]);
sourcepub async fn iter_mut(&mut self) -> Result<IterMut<'_, T>, ViewError>
pub async fn iter_mut(&mut self) -> Result<IterMut<'_, T>, ViewError>
Gets a mutable iterator on the entries of the queue
let mut queue = BucketQueueView::<_, u8, 5>::load(context).await.unwrap();
queue.push_back(34);
let mut iter = queue.iter_mut().await.unwrap();
let value = iter.next().unwrap();
*value = 42;
assert_eq!(queue.elements().await.unwrap(), vec![42]);
Trait Implementations§
source§impl<C, T, const N: usize> ClonableView<C> for BucketQueueView<C, T, N>
impl<C, T, const N: usize> ClonableView<C> for BucketQueueView<C, T, N>
source§fn clone_unchecked(&mut self) -> Result<Self, ViewError>
fn clone_unchecked(&mut self) -> Result<Self, ViewError>
source§impl<C, T, const N: usize> ContainerType for BucketQueueView<C, T, N>
impl<C, T, const N: usize> ContainerType for BucketQueueView<C, T, N>
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, T, const N: usize> HashableView<C> for BucketQueueView<C, T, N>
impl<C, T, const N: usize> HashableView<C> for BucketQueueView<C, T, N>
§type Hasher = CoreWrapper<Sha3_256Core>
type Hasher = CoreWrapper<Sha3_256Core>
source§impl<C, T, const N: usize> OutputType for BucketQueueView<C, T, N>
impl<C, T, const N: usize> OutputType for BucketQueueView<C, T, N>
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, T: OutputType, const N: usize> TypeName for BucketQueueView<C, T, N>
impl<C: Send + Sync, T: OutputType, const N: usize> TypeName for BucketQueueView<C, T, N>
source§impl<C, T, const N: usize> View<C> for BucketQueueView<C, T, N>
impl<C, T, const N: usize> View<C> for BucketQueueView<C, T, N>
source§const NUM_INIT_KEYS: usize = 2usize
const NUM_INIT_KEYS: usize = 2usize
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, T, const N: usize> ObjectType for BucketQueueView<C, T, N>
Auto Trait Implementations§
impl<C, T, const N: usize> Freeze for BucketQueueView<C, T, N>where
C: Freeze,
impl<C, T, const N: usize> RefUnwindSafe for BucketQueueView<C, T, N>where
C: RefUnwindSafe,
T: RefUnwindSafe,
impl<C, T, const N: usize> Send for BucketQueueView<C, T, N>
impl<C, T, const N: usize> Sync for BucketQueueView<C, T, N>
impl<C, T, const N: usize> Unpin for BucketQueueView<C, T, N>
impl<C, T, const N: usize> UnwindSafe for BucketQueueView<C, T, N>where
C: UnwindSafe,
T: 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
.