[−][src]Struct ink_storage::Pack
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>
is equivalent toi32
in its storage occupation. - A
Pack<(i32, i32)>
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]
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
impl<T> Pack<T>
[src]
pub fn new(value: T) -> Self
[src]
Creates a new packed value.
pub fn into_inner(pack: Self) -> T
[src]
Returns the packed value.
pub fn as_inner(pack: &Pack<T>) -> &T
[src]
Returns a shared reference to the packed value.
pub fn as_inner_mut(pack: &mut Pack<T>) -> &mut T
[src]
Returns an exclusive reference to the packed value.
Trait Implementations
impl<T> AsMut<T> for Pack<T>
[src]
impl<T> AsRef<T> for Pack<T>
[src]
impl<T> Borrow<T> for Pack<T>
[src]
impl<T> BorrowMut<T> for Pack<T>
[src]
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T: Clone> Clone for Pack<T>
[src]
impl<T: Copy> Copy for Pack<T>
[src]
impl<T: Debug> Debug for Pack<T>
[src]
impl<T> Decode for Pack<T> where
T: Decode,
T: Decode,
[src]
T: Decode,
T: Decode,
fn decode<__CodecInputEdqy: Input>(
__codec_input_edqy: &mut __CodecInputEdqy
) -> Result<Self, Error>
[src]
__codec_input_edqy: &mut __CodecInputEdqy
) -> Result<Self, Error>
impl<T> Default for Pack<T> where
T: Default,
[src]
T: Default,
impl<T> Deref for Pack<T>
[src]
impl<T> DerefMut for Pack<T>
[src]
impl<T> Display for Pack<T> where
T: Display,
[src]
T: Display,
impl<T> Encode for Pack<T> where
T: Encode,
T: Encode,
[src]
T: Encode,
T: Encode,
fn encode_to<__CodecOutputEdqy: Output>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy
)
[src]
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy
)
fn encode(&self) -> Vec<u8>
[src]
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R
[src]
fn size_hint(&self) -> usize
[src]
impl<T> EncodeLike<Pack<T>> for Pack<T> where
T: Encode,
T: Encode,
[src]
T: Encode,
T: Encode,
impl<T> Eq for Pack<T> where
T: Eq,
[src]
T: Eq,
impl<T> From<T> for Pack<T>
[src]
impl<T> Hash for Pack<T> where
T: Hash,
[src]
T: Hash,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> Ord for Pack<T> where
T: Ord,
[src]
T: Ord,
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<T> PackedLayout for Pack<T> where
T: PackedLayout,
[src]
T: PackedLayout,
fn pull_packed(&mut self, at: &Key)
[src]
fn push_packed(&self, at: &Key)
[src]
fn clear_packed(&self, at: &Key)
[src]
impl<T> PartialEq<Pack<T>> for Pack<T> where
T: PartialEq,
[src]
T: PartialEq,
impl<T> PartialOrd<Pack<T>> for Pack<T> where
T: PartialOrd,
[src]
T: PartialOrd,
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
fn lt(&self, other: &Self) -> bool
[src]
fn le(&self, other: &Self) -> bool
[src]
fn ge(&self, other: &Self) -> bool
[src]
fn gt(&self, other: &Self) -> bool
[src]
impl<T> SpreadLayout for Pack<T> where
T: PackedLayout,
[src]
T: PackedLayout,
const FOOTPRINT: u64
[src]
fn pull_spread(ptr: &mut KeyPtr) -> Self
[src]
fn push_spread(&self, ptr: &mut KeyPtr)
[src]
fn clear_spread(&self, ptr: &mut KeyPtr)
[src]
const REQUIRES_DEEP_CLEAN_UP: bool
[src]
impl<T> StorageLayout for Pack<T> where
T: TypeInfo + 'static,
[src]
T: TypeInfo + 'static,
Auto Trait Implementations
impl<T> RefUnwindSafe for Pack<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Pack<T> where
T: Send,
T: Send,
impl<T> Sync for Pack<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Pack<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Pack<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T, U> AsByteSlice<T> for U where
T: ToByteSlice,
U: AsRef<[T]> + ?Sized,
T: ToByteSlice,
U: AsRef<[T]> + ?Sized,
fn as_byte_slice(&self) -> &[u8]
impl<T, U> AsMutByteSlice<T> for U where
T: ToMutByteSlice,
U: AsMut<[T]> + ?Sized,
T: ToMutByteSlice,
U: AsMut<[T]> + ?Sized,
fn as_mut_byte_slice(&mut self) -> &mut [u8]
impl<U> AsMutSliceOf for U where
U: AsMut<[u8]> + ?Sized,
U: AsMut<[u8]> + ?Sized,
fn as_mut_slice_of<T>(&mut self) -> Result<&mut [T], Error> where
T: FromByteSlice,
T: FromByteSlice,
impl<U> AsSliceOf for U where
U: AsRef<[u8]> + ?Sized,
U: AsRef<[u8]> + ?Sized,
fn as_slice_of<T>(&self) -> Result<&[T], Error> where
T: FromByteSlice,
T: FromByteSlice,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<S> Codec for S where
S: Encode + Decode,
[src]
S: Encode + Decode,
impl<T, X> Decode for X where
T: Decode + Into<X>,
X: WrapperTypeDecode<Wrapped = T>,
[src]
T: Decode + Into<X>,
X: WrapperTypeDecode<Wrapped = T>,
impl<T> DecodeAll for T where
T: Decode,
[src]
T: Decode,
impl<T> DecodeLimit for T where
T: Decode,
[src]
T: Decode,
fn decode_all_with_depth_limit(limit: u32, input: &[u8]) -> Result<T, Error>
[src]
fn decode_with_depth_limit(limit: u32, input: &[u8]) -> Result<T, Error>
[src]
impl<T, X> Encode for X where
T: Encode + ?Sized,
X: WrapperTypeEncode<Target = T>,
[src]
T: Encode + ?Sized,
X: WrapperTypeEncode<Target = T>,
fn size_hint(&self) -> usize
[src]
fn using_encoded<R, F>(&self, f: F) -> R where
F: FnOnce(&[u8]) -> R,
[src]
F: FnOnce(&[u8]) -> R,
fn encode(&self) -> Vec<u8>
[src]
fn encode_to<W>(&self, dest: &mut W) where
W: Output,
[src]
W: Output,
impl<'_, '_, T> EncodeLike<&'_ &'_ T> for T where
T: Encode,
[src]
T: Encode,
impl<'_, T> EncodeLike<&'_ T> for T where
T: Encode,
[src]
T: Encode,
impl<'_, T> EncodeLike<&'_ mut T> for T where
T: Encode,
[src]
T: Encode,
impl<T> EncodeLike<Arc<T>> for T where
T: Encode,
[src]
T: Encode,
impl<T> EncodeLike<Box<T>> for T where
T: Encode,
[src]
T: Encode,
impl<'a, T> EncodeLike<Cow<'a, T>> for T where
T: Encode + ToOwned,
[src]
T: Encode + ToOwned,
impl<T> EncodeLike<Rc<T>> for T where
T: Encode,
[src]
T: Encode,
impl<T> From<!> for T
[src]
impl<T> From<T> for T
[src]
impl<S> FullCodec for S where
S: Decode + FullEncode,
[src]
S: Decode + FullEncode,
impl<S> FullEncode for S where
S: Encode + EncodeLike<S>,
[src]
S: Encode + EncodeLike<S>,
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> KeyedVec for T where
T: Codec,
[src]
T: Codec,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,