pub struct StorageBytes { /* private fields */ }
Expand description
Accessor for storage-backed bytes.
Implementations§
Source§impl StorageBytes
impl StorageBytes
Sourcepub unsafe fn set_len(&mut self, len: usize)
pub unsafe fn set_len(&mut self, len: usize)
Overwrites the collection’s length, moving bytes as needed.
§Safety
May populate the vector with junk bytes from prior dirty operations.
Note that StorageBytes
has unlimited capacity, so all lengths are valid.
Sourcepub fn pop(&mut self) -> Option<u8>
pub fn pop(&mut self) -> Option<u8>
Removes and returns the last byte, if it exists. As an optimization, underlying storage slots are only erased when all bytes in a given word are freed when in the multi-word representation.
Sourcepub fn get(&self, index: impl TryInto<usize>) -> Option<u8>
pub fn get(&self, index: impl TryInto<usize>) -> Option<u8>
Gets the byte at the given index, if it exists.
Sourcepub fn get_mut(
&mut self,
index: impl TryInto<usize>,
) -> Option<StorageGuardMut<'_, StorageB8>>
pub fn get_mut( &mut self, index: impl TryInto<usize>, ) -> Option<StorageGuardMut<'_, StorageB8>>
Gets a mutable accessor to the byte at the given index, if it exists.
Sourcepub unsafe fn get_unchecked(&self, index: usize) -> u8
pub unsafe fn get_unchecked(&self, index: usize) -> u8
Gets the byte at the given index, even if beyond the collection.
§Safety
UB if index is out of bounds.
Trait Implementations§
Source§impl Erase for StorageBytes
impl Erase for StorageBytes
Source§impl<'a> Extend<&'a u8> for StorageBytes
impl<'a> Extend<&'a u8> for StorageBytes
Source§fn extend<T: IntoIterator<Item = &'a u8>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a u8>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl Extend<u8> for StorageBytes
impl Extend<u8> for StorageBytes
Source§fn extend<T: IntoIterator<Item = u8>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = u8>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<T> From<&T> for StorageBytes
impl<T> From<&T> for StorageBytes
Source§impl HostAccess for StorageBytes
impl HostAccess for StorageBytes
Source§impl StorageType for StorageBytes
impl StorageType for StorageBytes
Source§type Wraps<'a> = StorageGuard<'a, StorageBytes>
where
Self: 'a
type Wraps<'a> = StorageGuard<'a, StorageBytes> where Self: 'a
For primitive types, this is the type being stored.
For collections, this is the
StorageType
being collected.Source§type WrapsMut<'a> = StorageGuardMut<'a, StorageBytes>
where
Self: 'a
type WrapsMut<'a> = StorageGuardMut<'a, StorageBytes> where Self: 'a
Mutable accessor to the type being stored.
Source§unsafe fn new(root: U256, offset: u8, host: VM) -> Self
unsafe fn new(root: U256, offset: u8, host: VM) -> Self
Where in persistent storage the type should live. Although useful for framework designers
creating new storage types, most user programs shouldn’t call this.
Note: implementations will have to be
const
once generic_const_exprs
stabilizes. Read moreSource§fn load<'s>(self) -> Self::Wraps<'s>
fn load<'s>(self) -> Self::Wraps<'s>
Load the wrapped type, consuming the accessor.
Note: most types have a
get
and/or getter
, which don’t consume Self
.Source§fn load_mut<'s>(self) -> Self::WrapsMut<'s>
fn load_mut<'s>(self) -> Self::WrapsMut<'s>
Load the wrapped mutable type, consuming the accessor.
Note: most types have a
set
and/or setter
, which don’t consume Self
.Source§const SLOT_BYTES: usize = 32usize
const SLOT_BYTES: usize = 32usize
The number of bytes in a slot needed to represent the type. Must not exceed 32.
For types larger than 32 bytes that are stored inline with a struct’s fields,
set this to 32 and return the full size in
StorageType::new
. Read moreSource§const REQUIRED_SLOTS: usize = 0usize
const REQUIRED_SLOTS: usize = 0usize
The number of words this type must fill. For primitives this is always 0.
For complex types requiring more than one inline word, set this to the total size.
Auto Trait Implementations§
impl !Freeze for StorageBytes
impl !RefUnwindSafe for StorageBytes
impl !Send for StorageBytes
impl !Sync for StorageBytes
impl Unpin for StorageBytes
impl !UnwindSafe for StorageBytes
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 more