Struct frame_support::storage::weak_bounded_vec::WeakBoundedVec [−][src]
pub struct WeakBoundedVec<T, S>(_, _);
Expand description
A weakly bounded vector.
It has implementations for efficient append and length decoding, as with a normal Vec<_>
, once
put into storage as a raw value, map or double-map.
The length of the vec is not strictly bounded. Decoding a vec with more element that the bound is accepted, and some method allow to bypass the restriction with warnings.
Implementations
Consume self, and return the inner Vec
. Henceforth, the Vec<_>
can be altered in an
arbitrary way. At some point, if the reverse conversion is required, TryFrom<Vec<_>>
can
be used.
This is useful for cases if you need access to an internal API of the inner Vec<_>
which
is not provided by the wrapper WeakBoundedVec
.
pub fn get_mut<I: SliceIndex<[T]>>(
&mut self,
index: I
) -> Option<&mut <I as SliceIndex<[T]>>::Output>
pub fn get_mut<I: SliceIndex<[T]>>(
&mut self,
index: I
) -> Option<&mut <I as SliceIndex<[T]>>::Output>
Exactly the same semantics as [Vec::get_mut
].
Create Self
from t
without any checks. Logs warnings if the bound is not being
respected. The additional scope can be used to indicate where a potential overflow is
happening.
Consumes self and mutates self via the given mutate
function.
If the outcome of mutation is within bounds, Some(Self)
is returned. Else, None
is
returned.
This is essentially a consuming shorthand Self::into_inner
-> ...
->
Self::try_from
.
Exactly the same semantics as Vec::insert
, but returns an Err
(and is a noop) if the
new length of the vector exceeds S
.
Panics
Panics if index > len
.
Methods from Deref<Target = Vec<T>>
Returns the number of elements the vector can hold without reallocating.
Examples
let vec: Vec<i32> = Vec::with_capacity(10); assert_eq!(vec.capacity(), 10);
Extracts a slice containing the entire vector.
Equivalent to &s[..]
.
Examples
use std::io::{self, Write}; let buffer = vec![1, 2, 3, 5, 8]; io::sink().write(buffer.as_slice()).unwrap();
Returns a raw pointer to the vector’s buffer.
The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage. Modifying the vector may cause its buffer to be reallocated, which would also make any pointers to it invalid.
The caller must also ensure that the memory the pointer (non-transitively) points to
is never written to (except inside an UnsafeCell
) using this pointer or any pointer
derived from it. If you need to mutate the contents of the slice, use as_mut_ptr
.
Examples
let x = vec![1, 2, 4]; let x_ptr = x.as_ptr(); unsafe { for i in 0..x.len() { assert_eq!(*x_ptr.add(i), 1 << i); } }
🔬 This is a nightly-only experimental API. (allocator_api
)
allocator_api
)Returns a reference to the underlying allocator.
Returns the number of elements in the vector, also referred to as its ‘length’.
Examples
let a = vec![1, 2, 3]; assert_eq!(a.len(), 3);
Trait Implementations
Attempt to deserialise the value from input.
Attempt to skip the encoded value from input. Read more
fn encoded_fixed_size() -> Option<usize>
fn encoded_fixed_size() -> Option<usize>
Returns the fixed encoded size of the type. Read more
impl<T, S> Encode for WeakBoundedVec<T, S> where
Vec<T>: Encode,
Vec<T>: Encode,
PhantomData<S>: Encode,
PhantomData<S>: Encode,
impl<T, S> Encode for WeakBoundedVec<T, S> where
Vec<T>: Encode,
Vec<T>: Encode,
PhantomData<S>: Encode,
PhantomData<S>: Encode,
Convert self to a slice and append it to the destination.
Convert self to an owned vector.
fn using_encoded<R, F>(&self, f: F) -> R where
F: FnOnce(&[u8]) -> R,
fn using_encoded<R, F>(&self, f: F) -> R where
F: FnOnce(&[u8]) -> R,
Convert self to a slice and then invoke the given closure with it.
fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Calculates the encoded size. Read more
impl<T, S> MaxEncodedLen for WeakBoundedVec<T, S> where
T: MaxEncodedLen,
S: Get<u32>,
WeakBoundedVec<T, S>: Encode,
impl<T, S> MaxEncodedLen for WeakBoundedVec<T, S> where
T: MaxEncodedLen,
S: Get<u32>,
WeakBoundedVec<T, S>: Encode,
Upper bound, in bytes, of the maximum encoded size of this item.
impl<T, S> EncodeLike<WeakBoundedVec<T, S>> for WeakBoundedVec<T, S> where
Vec<T>: Encode,
Vec<T>: Encode,
PhantomData<S>: Encode,
PhantomData<S>: Encode,
Auto Trait Implementations
impl<T, S> RefUnwindSafe for WeakBoundedVec<T, S> where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S> Send for WeakBoundedVec<T, S> where
S: Send,
T: Send,
impl<T, S> Sync for WeakBoundedVec<T, S> where
S: Sync,
T: Sync,
impl<T, S> Unpin for WeakBoundedVec<T, S> where
S: Unpin,
T: Unpin,
impl<T, S> UnwindSafe for WeakBoundedVec<T, S> where
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
pub fn as_mut_slice_of<T>(&mut self) -> Result<&mut [T], Error> where
T: FromByteSlice,
pub fn as_slice_of<T>(&self) -> Result<&[T], Error> where
T: FromByteSlice,
Mutably borrows from an owned value. Read more
impl<T> DecodeAll for T where
T: Decode,
impl<T> DecodeAll for T where
T: Decode,
impl<T> DecodeLimit for T where
T: Decode,
impl<T> DecodeLimit for T where
T: Decode,
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
impl<T> KeyedVec for T where
T: Codec,
impl<T> KeyedVec for T where
T: Codec,
type Output = T
type Output = T
Should always be Self
The counterpart to unchecked_from
.
Consume self to return an equivalent value of T
.
pub fn vzip(self) -> V
impl<'_, '_, T> EncodeLike<&'_ &'_ T> for T where
T: Encode,
impl<'_, T> EncodeLike<&'_ T> for T where
T: Encode,
impl<'_, T> EncodeLike<&'_ mut T> for T where
T: Encode,
impl<T> EncodeLike<Arc<T>> for T where
T: Encode,
impl<T> EncodeLike<Box<T, Global>> for T where
T: Encode,
impl<'a, T> EncodeLike<Cow<'a, T>> for T where
T: ToOwned + Encode,
impl<T> EncodeLike<Rc<T>> for T where
T: Encode,
impl<S> FullCodec for S where
S: Decode + FullEncode,
impl<S> FullEncode for S where
S: Encode + EncodeLike<S>,
impl<T> MaybeDebug for T where
T: Debug,
impl<T> MaybeDebug for T where
T: Debug,