pub struct Weight(/* private fields */);Expand description
The weight of a transaction or block.
This is an integer newtype representing weight in weight units. It provides protection against mixing up the types, conversion functions, and basic formatting.
Implementations§
Source§impl Weight
impl Weight
Sourcepub const ZERO: Self
pub const ZERO: Self
Zero weight units (wu).
Equivalent to MIN, may better express intent in some contexts.
Sourcepub const MIN: Self
pub const MIN: Self
Minimum possible value (0 wu).
Equivalent to ZERO, may better express intent in some contexts.
Sourcepub const WITNESS_SCALE_FACTOR: u64
pub const WITNESS_SCALE_FACTOR: u64
The factor that non-witness serialization data is multiplied by during weight calculation.
Sourcepub const MIN_TRANSACTION: Self
pub const MIN_TRANSACTION: Self
The minimum transaction weight for a valid serialized transaction.
Sourcepub const fn from_vb_unwrap(vb: u64) -> Self
👎Deprecated since 1.0.0-rc.0: use from_vb_unchecked instead
pub const fn from_vb_unwrap(vb: u64) -> Self
from_vb_unchecked insteadSourcepub const fn from_vb_unchecked(vb: u64) -> Self
pub const fn from_vb_unchecked(vb: u64) -> Self
Constructs a new Weight from virtual bytes without an overflow check.
Sourcepub const fn from_witness_data_size(witness_size: u64) -> Self
👎Deprecated since 1.0.0-rc.1: use from_wu instead
pub const fn from_witness_data_size(witness_size: u64) -> Self
from_wu insteadConstructs a new Weight from witness size.
Sourcepub const fn from_non_witness_data_size(non_witness_size: u64) -> Self
👎Deprecated since 1.0.0-rc.1: use from_vb or from_vb_unchecked instead
pub const fn from_non_witness_data_size(non_witness_size: u64) -> Self
from_vb or from_vb_unchecked insteadSourcepub const fn to_kwu_floor(self) -> u64
pub const fn to_kwu_floor(self) -> u64
Converts to kilo weight units rounding down.
Sourcepub const fn to_kwu_ceil(self) -> u64
pub const fn to_kwu_ceil(self) -> u64
Converts to kilo weight units rounding up.
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 const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Checked addition.
Computes self + rhs returning None if an overflow occurred.
Sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Checked subtraction.
Computes self - rhs returning None if an overflow occurred.
Sourcepub const fn checked_mul(self, rhs: u64) -> Option<Self>
pub const fn checked_mul(self, rhs: u64) -> Option<Self>
Checked multiplication.
Computes self * rhs returning None if an overflow occurred.
Sourcepub const fn checked_div(self, rhs: u64) -> Option<Self>
pub const fn checked_div(self, rhs: u64) -> Option<Self>
Checked division.
Computes self / rhs returning None if rhs == 0.
Sourcepub const fn mul_by_fee_rate(self, fee_rate: FeeRate) -> NumOpResult<Amount>
pub const fn mul_by_fee_rate(self, fee_rate: FeeRate) -> NumOpResult<Amount>
Checked fee rate multiplication.
Computes the absolute fee amount for a given FeeRate at this weight. When the resulting
fee is a non-integer amount, the amount is rounded up, ensuring that the transaction fee is
enough instead of falling short if rounded down.
Trait Implementations§
Source§impl AddAssign<&Weight> for Weight
impl AddAssign<&Weight> for Weight
Source§fn add_assign(&mut self, rhs: &Weight)
fn add_assign(&mut self, rhs: &Weight)
+= operation. Read moreSource§impl AddAssign for Weight
impl AddAssign for Weight
Source§fn add_assign(&mut self, rhs: Weight)
fn add_assign(&mut self, rhs: Weight)
+= operation. Read moreSource§impl<'a> Arbitrary<'a> for Weight
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for Weight
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl<'de> Deserialize<'de> for Weight
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Weight
serde only.Source§fn deserialize<D>(d: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(d: 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 RemAssign<u64> for Weight
impl RemAssign<u64> for Weight
Source§fn rem_assign(&mut self, rhs: u64)
fn rem_assign(&mut self, rhs: u64)
%= operation. Read moreSource§impl SubAssign<&Weight> for Weight
impl SubAssign<&Weight> for Weight
Source§fn sub_assign(&mut self, rhs: &Weight)
fn sub_assign(&mut self, rhs: &Weight)
-= operation. Read moreSource§impl SubAssign for Weight
impl SubAssign for Weight
Source§fn sub_assign(&mut self, rhs: Weight)
fn sub_assign(&mut self, rhs: Weight)
-= operation. Read more