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§
§impl Weight
impl Weight
pub const MIN: Weight = _
pub const MIN: Weight = _
Minimum possible value (0 wu).
Equivalent to ZERO
, may better express intent in some contexts.
pub const WITNESS_SCALE_FACTOR: u64 = 4u64
pub const WITNESS_SCALE_FACTOR: u64 = 4u64
The factor that non-witness serialization data is multiplied by during weight calculation.
pub const MIN_TRANSACTION: Weight = _
pub const MIN_TRANSACTION: Weight = _
The minimum transaction weight for a valid serialized transaction.
pub const fn from_wu_usize(wu: usize) -> Weight
pub const fn from_wu_usize(wu: usize) -> Weight
Directly constructs Weight
from usize weight units.
pub fn from_kwu(wu: u64) -> Option<Weight>
pub fn from_kwu(wu: u64) -> Option<Weight>
Constructs Weight
from kilo weight units returning None
if an overflow occurred.
pub fn from_vb(vb: u64) -> Option<Weight>
pub fn from_vb(vb: u64) -> Option<Weight>
Constructs Weight
from virtual bytes, returning None
on overflow.
pub const fn from_vb_unwrap(vb: u64) -> Weight
pub const fn from_vb_unwrap(vb: u64) -> Weight
Constructs Weight
from virtual bytes panicking on overflow.
§Panics
If the conversion from virtual bytes overflows.
pub const fn from_vb_unchecked(vb: u64) -> Weight
pub const fn from_vb_unchecked(vb: u64) -> Weight
Constructs Weight
from virtual bytes without an overflow check.
pub const fn from_witness_data_size(witness_size: u64) -> Weight
pub const fn from_witness_data_size(witness_size: u64) -> Weight
Constructs Weight
from witness size.
pub const fn from_non_witness_data_size(non_witness_size: u64) -> Weight
pub const fn from_non_witness_data_size(non_witness_size: u64) -> Weight
Constructs Weight
from non-witness size.
pub 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.
pub const fn to_kwu_floor(self) -> u64
pub const fn to_kwu_floor(self) -> u64
Converts to kilo weight units rounding down.
pub const fn to_vbytes_floor(self) -> u64
pub const fn to_vbytes_floor(self) -> u64
Converts to vB rounding down.
pub const fn to_vbytes_ceil(self) -> u64
pub const fn to_vbytes_ceil(self) -> u64
Converts to vB rounding up.
pub fn checked_add(self, rhs: Weight) -> Option<Weight>
pub fn checked_add(self, rhs: Weight) -> Option<Weight>
Checked addition.
Computes self + rhs
returning None
if an overflow occurred.
pub fn checked_sub(self, rhs: Weight) -> Option<Weight>
pub fn checked_sub(self, rhs: Weight) -> Option<Weight>
Checked subtraction.
Computes self - rhs
returning None
if an overflow occurred.
pub fn checked_mul(self, rhs: u64) -> Option<Weight>
pub fn checked_mul(self, rhs: u64) -> Option<Weight>
Checked multiplication.
Computes self * rhs
returning None
if an overflow occurred.
pub fn checked_div(self, rhs: u64) -> Option<Weight>
pub fn checked_div(self, rhs: u64) -> Option<Weight>
Checked division.
Computes self / rhs
returning None
if rhs == 0
.
pub fn scale_by_witness_factor(self) -> Option<Weight>
pub fn scale_by_witness_factor(self) -> Option<Weight>
Scale by witness factor.
Computes self * WITNESS_SCALE_FACTOR
returning None
if an overflow occurred.
Trait Implementations§
§impl AddAssign for Weight
impl AddAssign for Weight
§fn add_assign(&mut self, rhs: Weight)
fn add_assign(&mut self, rhs: Weight)
+=
operation. Read more§impl<'de> Deserialize<'de> for Weight
impl<'de> Deserialize<'de> for Weight
§fn deserialize<__D>(
__deserializer: __D
) -> Result<Weight, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Weight, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl DivAssign<u64> for Weight
impl DivAssign<u64> for Weight
§fn div_assign(&mut self, rhs: u64)
fn div_assign(&mut self, rhs: u64)
/=
operation. Read more§impl MulAssign<u64> for Weight
impl MulAssign<u64> for Weight
§fn mul_assign(&mut self, rhs: u64)
fn mul_assign(&mut self, rhs: u64)
*=
operation. Read more§impl Ord for Weight
impl Ord for Weight
§impl PartialOrd for Weight
impl PartialOrd for Weight
§fn partial_cmp(&self, other: &Weight) -> Option<Ordering>
fn partial_cmp(&self, other: &Weight) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more§impl Serialize for Weight
impl Serialize for Weight
§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
§impl SubAssign for Weight
impl SubAssign for Weight
§fn sub_assign(&mut self, rhs: Weight)
fn sub_assign(&mut self, rhs: Weight)
-=
operation. Read more