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 to i32 in its storage occupation.
  • A Pack<(i32, i32)> instance will occupy a single cell compared to (i32, i32) which occupies a cell per i32.
  • A Lazy<Pack<[u8; 8]>> lazily loads a Pack<[u8; 8]> which occupies a single cell whereas a [u8; 8] array would occupy 8 cells in total, one for each u8.
  • Rust collections will never use more than a single cell. So Pack<LinkedList<T>> and LinkedList<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 the PackedLayout trait. For example storage::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

Creates a new packed value.

Returns a shared reference to the packed value.

Returns an exclusive reference to the packed value.

Trait Implementations

Performs the conversion.

Performs the conversion.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Attempt to deserialise the value from input.

Attempt to skip the encoded value from input. Read more

Returns the fixed encoded size of the type. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

If possible give a hint of expected size of the encoding. Read more

Convert self to a slice and append it to the destination.

Convert self to an owned vector.

Convert self to a slice and then invoke the given closure with it.

Calculates the encoded size. Read more

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

Indicates to self that is has just been pulled from the storage. Read more

Indicates to self that it is about to be pushed to contract storage. Read more

Indicates to self that it is about to be cleared from contract storage. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than (for self and other) and is used by the > operator. Read more

The footprint of the type. 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

Returns the static storage layout of Self. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Decode Self and consume all of the given input data. Read more

Decode Self and consume all of the given input data. Read more

Decode Self and advance input by the number of bytes consumed. Read more

Decode Self with the given maximum recursion depth. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Return an encoding of Self prepended by given slice.

Should always be Self

Convert from a value of T into an equivalent instance of Self. Read more

Consume self to return an equivalent value of T. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Consume self to return an equivalent value of T.