Struct bitcoin_units::weight::Weight
source · 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 ZERO: Weight = _
pub const ZERO: Weight = _
0 wu.
Equivalent to MIN
, may better express intent in some contexts.
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 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.
sourcepub const MAX_BLOCK: Weight = _
pub const MAX_BLOCK: Weight = _
The maximum allowed weight for a block, see BIP 141 (network rule).
sourcepub const MIN_TRANSACTION: Weight = _
pub const MIN_TRANSACTION: Weight = _
The minimum transaction weight for a valid serialized transaction.
sourcepub const fn from_wu_usize(wu: usize) -> Self
pub const fn from_wu_usize(wu: usize) -> Self
Directly constructs Weight
from usize weight units.
sourcepub fn from_kwu(wu: u64) -> Option<Self>
pub fn from_kwu(wu: u64) -> Option<Self>
Constructs Weight
from kilo weight units returning None
if an overflow occurred.
sourcepub fn from_vb(vb: u64) -> Option<Self>
pub fn from_vb(vb: u64) -> Option<Self>
Constructs Weight
from virtual bytes, returning None
on overflow.
sourcepub 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.
sourcepub const fn from_vb_unchecked(vb: u64) -> Self
pub const fn from_vb_unchecked(vb: u64) -> Self
Constructs Weight
from virtual bytes without an 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_kwu_floor(self) -> u64
pub const fn to_kwu_floor(self) -> u64
Converts to kilo weight units rounding down.
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 an 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 an 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 an 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
.
sourcepub fn scale_by_witness_factor(self) -> Option<Self>
pub fn scale_by_witness_factor(self) -> Option<Self>
Scale by witness factor.
Computes self * WITNESS_SCALE_FACTOR
returning None
if an overflow occurred.
Trait Implementations§
source§impl AddAssign<Weight> for Weight
impl AddAssign<Weight> 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 PartialEq<Weight> for Weight
impl PartialEq<Weight> for Weight
source§impl PartialOrd<Weight> for Weight
impl PartialOrd<Weight> for Weight
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 moresource§impl SubAssign<Weight> for Weight
impl SubAssign<Weight> for Weight
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read more