pub struct Weight(/* private fields */);Expand description
Represents block weight - the weight of a transaction or block.
This is an integer newtype representing weigth in wu. It provides protection against mixing
up the types as well as basic formatting features.
Implementations§
Source§impl Weight
impl Weight
Sourcepub const MIN: Weight
pub const MIN: Weight
Minimum possible value (0 wu).
Equivalent to ZERO, may better express intent in some contexts.
Sourcepub const fn from_vb_unchecked(vb: u64) -> Self
pub const fn from_vb_unchecked(vb: u64) -> Self
Constructs Weight from virtual bytes without overflow check.
Sourcepub const fn from_witness_data_size(witness_size: u64) -> Self
pub const fn from_witness_data_size(witness_size: u64) -> Self
Constructs Weight from witness size.
Sourcepub const fn from_non_witness_data_size(non_witness_size: u64) -> Self
pub const fn from_non_witness_data_size(non_witness_size: u64) -> Self
Constructs Weight from non-witness size.
Sourcepub const fn to_wu(self) -> u64
pub const fn to_wu(self) -> u64
Returns raw weight units.
Can be used instead of into() to avoid inference issues.
Sourcepub const fn to_vbytes_floor(self) -> u64
pub const fn to_vbytes_floor(self) -> u64
Converts to vB rounding down.
Sourcepub const fn to_vbytes_ceil(self) -> u64
pub const fn to_vbytes_ceil(self) -> u64
Converts to vB rounding up.
Sourcepub fn checked_add(self, rhs: Self) -> Option<Self>
pub fn checked_add(self, rhs: Self) -> Option<Self>
Checked addition.
Computes self + rhs returning None if overflow occurred.
Sourcepub fn checked_sub(self, rhs: Self) -> Option<Self>
pub fn checked_sub(self, rhs: Self) -> Option<Self>
Checked subtraction.
Computes self - rhs returning None if overflow occurred.
Sourcepub fn checked_mul(self, rhs: u64) -> Option<Self>
pub fn checked_mul(self, rhs: u64) -> Option<Self>
Checked multiplication.
Computes self * rhs returning None if overflow occurred.
Sourcepub fn checked_div(self, rhs: u64) -> Option<Self>
pub fn checked_div(self, rhs: u64) -> Option<Self>
Checked division.
Computes self / rhs returning None if rhs == 0.
Trait Implementations§
Source§impl AddAssign for Weight
impl AddAssign for Weight
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for Weight
impl<'de> Deserialize<'de> for Weight
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl DivAssign<u64> for Weight
impl DivAssign<u64> for Weight
Source§fn div_assign(&mut self, rhs: u64)
fn div_assign(&mut self, rhs: u64)
/= operation. Read moreSource§impl MulAssign<u64> for Weight
impl MulAssign<u64> for Weight
Source§fn mul_assign(&mut self, rhs: u64)
fn mul_assign(&mut self, rhs: u64)
*= operation. Read moreSource§impl Ord for Weight
impl Ord for Weight
Source§impl PartialOrd for Weight
impl PartialOrd for Weight
Source§impl SubAssign for Weight
impl SubAssign for Weight
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more