Struct ink_storage::Pack [−][src]
pub struct Pack<T> where
T: PackedLayout, { /* fields omitted */ }
Expand description
Packs the inner T
so that it only occupies a single contract storage cell.
Note
This is an important modular building stone in order to manage contract
storage occupation. By default, types try to distribute themselves onto
their respective contract storage area. However, upon packing them into
Pack<T>
they will be compressed to only ever make use of a single
contract storage cell. Sometimes this can be advantageous for performance
reasons.
Usage
- A
Pack<i32>
instance is equivalent toi32
in its storage occupation. - A
Pack<(i32, i32)>
instance will occupy a single cell compared to(i32, i32)
which occupies a cell peri32
. - A
Lazy<Pack<[u8; 8]>>
lazily loads aPack<[u8; 8]>
which occupies a single cell whereas a[u8; 8]
array would occupy 8 cells in total, one for eachu8
. - Rust collections will never use more than a single cell. So
Pack<LinkedList<T>>
andLinkedList<T>
will occupy the same amount of cells, namely 1. - Packs can be packed. So for example a
Pack<(Pack<(i32, i32)>, Pack<[u8; 8]>)
uses just one cell instead of two cells which is the case for(Pack<(i32, i32)>, Pack<[u8; 8]>)
. - Not all
storage
types can be packed. Only those that are implementing thePackedLayout
trait. For examplestorage::Vec<T>
does not implement this trait and thus cannot be packed.
As a general advice pack values together that are frequently used together.
Also pack many very small elements (e.g. u8
, bool
, u16
) together.
Implementations
Trait Implementations
Mutably borrows from an owned value. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
Pulls an instance of Self
from the contract storage. Read more
Pushes an instance of Self
to the contract storage. Read more
Clears an instance of Self
from the contract storage. Read more
Indicates whether a type requires deep clean-up of its state meaning that
a clean-up routine has to decode an entity into an instance in order to
eventually recurse upon its tear-down.
This is not required for the majority of primitive data types such as i32
,
however types such as storage::Box
that might want to forward the clean-up
procedure to their inner T
require a deep clean-up. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for Pack<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Pack<T> where
T: UnwindSafe,
Blanket Implementations
pub fn as_byte_slice(&self) -> &[u8]
pub fn as_mut_byte_slice(&mut self) -> &mut [u8]
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
fn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
Convert from a value of T
into an equivalent instance of Self
. Read more
fn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
Consume self to return an equivalent value of T
. Read more
pub fn unique_saturated_into(self) -> T
pub fn unique_saturated_into(self) -> T
Consume self to return an equivalent value of T
.