#[repr(transparent)]pub struct Weight<T>(pub T);
Expand description
The Weight
type is a wrapper around a generic type T
that provides additional
functionality for working with weights in a graph context.
Tuple Fields§
§0: T
Implementations§
Source§impl<T> Weight<T>
the base implemenation of Weight
that is generic over type T
impl<T> Weight<T>
the base implemenation of Weight
that is generic over type T
Sourcepub const fn new(value: T) -> Self
pub const fn new(value: T) -> Self
returns a new instance of the Weight
created from the given value.
Sourcepub fn new_with<F>(value: F) -> Selfwhere
F: FnOnce() -> T,
pub fn new_with<F>(value: F) -> Selfwhere
F: FnOnce() -> T,
generates a new instance of the Weight
using the provided function
Sourcepub fn default() -> Selfwhere
T: Default,
pub fn default() -> Selfwhere
T: Default,
returns a new instance of the Weight
with the default value of the inner type.
Sourcepub fn one() -> Selfwhere
T: One,
pub fn one() -> Selfwhere
T: One,
returns a new instance of the Weight
with the inner value set to 1
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
consumes the current instance to return the inner value
Sourcepub fn map<U, F>(self, f: F) -> Weight<U>where
F: FnOnce(T) -> U,
pub fn map<U, F>(self, f: F) -> Weight<U>where
F: FnOnce(T) -> U,
applies the provided function onto the inner value and returns a new Weight
with
the result.
Sourcepub fn map_mut<F>(&mut self, f: F) -> &mut Self
pub fn map_mut<F>(&mut self, f: F) -> &mut Self
apply the function onto a mutable reference to the inner value and return a mutable reference to the current instanc storing the updating weight.
Sourcepub const fn replace(&mut self, value: T) -> T
pub const fn replace(&mut self, value: T) -> T
replace
the inner value and return the previous value.
Sourcepub fn set(&mut self, value: T) -> &mut Self
pub fn set(&mut self, value: T) -> &mut Self
updates the inner value with the provided value and returns a mutable reference to the current instance.
Sourcepub fn take(&mut self) -> Twhere
T: Default,
pub fn take(&mut self) -> Twhere
T: Default,
take
the inner value, leaving the logical default in its place.
Sourcepub const fn as_ptr(&self) -> *const T
pub const fn as_ptr(&self) -> *const T
returns a constant pointer to the inner value; see core::ptr::addr_of!
for more
information
Sourcepub const fn as_mut_ptr(&mut self) -> *mut T
pub const fn as_mut_ptr(&mut self) -> *mut T
returns a mutable pointer to the inner value; see core::ptr::addr_of_mut!
for more
information
Sourcepub const fn view(&self) -> Weight<&T>
pub const fn view(&self) -> Weight<&T>
returns a view of the weight whose inner value is a reference to the original.
Sourcepub const fn view_mut(&mut self) -> Weight<&mut T>
pub const fn view_mut(&mut self) -> Weight<&mut T>
returns a view of the weight whose inner value is a mutable reference to the original
Sourcepub fn with<U>(self, value: U) -> Weight<U>
pub fn with<U>(self, value: U) -> Weight<U>
consumes the current instance to create another with the given value
Sourcepub fn is_weighted(&self) -> bool
pub fn is_weighted(&self) -> bool
returns true if:
- the weight is not of type
Weightless
- the inner value is not the default value of the type
T
rather than simply checking if the weight is not of type Weightless
, this method
includes additional assertions for quickly checking the state of a weight.
Sourcepub fn is_weightless(&self) -> boolwhere
T: 'static,
pub fn is_weightless(&self) -> boolwhere
T: 'static,
returns true if the weight is of type Weightless
Source§impl<T> Weight<UnWeight<T>>
impl<T> Weight<UnWeight<T>>
Sourcepub const fn unweighted() -> Self
pub const fn unweighted() -> Self
returns a new [Unweighted
] instance with the inner value of type T
.
Sourcepub fn init_with<F>(self, f: F) -> Weight<T>where
F: FnOnce() -> T,
pub fn init_with<F>(self, f: F) -> Weight<T>where
F: FnOnce() -> T,
returns a new Weight
of type T
initialized using the provided closure f
Sourcepub fn init_default(self) -> Weight<T>where
T: Default,
pub fn init_default(self) -> Weight<T>where
T: Default,
returns a new Weight
initialized using the logical default for type T
Trait Implementations§
Source§impl<A, B> AddAssign<Weight<B>> for &mut Weight<A>where
A: AddAssign<B>,
impl<A, B> AddAssign<Weight<B>> for &mut Weight<A>where
A: AddAssign<B>,
Source§fn add_assign(&mut self, rhs: Weight<B>)
fn add_assign(&mut self, rhs: Weight<B>)
+=
operation. Read moreSource§impl<A, B> AddAssign<Weight<B>> for Weight<A>where
A: AddAssign<B>,
impl<A, B> AddAssign<Weight<B>> for Weight<A>where
A: AddAssign<B>,
Source§fn add_assign(&mut self, rhs: Weight<B>)
fn add_assign(&mut self, rhs: Weight<B>)
+=
operation. Read moreSource§impl<A, B> BitAndAssign<Weight<B>> for &mut Weight<A>where
A: BitAndAssign<B>,
impl<A, B> BitAndAssign<Weight<B>> for &mut Weight<A>where
A: BitAndAssign<B>,
Source§fn bitand_assign(&mut self, rhs: Weight<B>)
fn bitand_assign(&mut self, rhs: Weight<B>)
&=
operation. Read moreSource§impl<A, B> BitAndAssign<Weight<B>> for Weight<A>where
A: BitAndAssign<B>,
impl<A, B> BitAndAssign<Weight<B>> for Weight<A>where
A: BitAndAssign<B>,
Source§fn bitand_assign(&mut self, rhs: Weight<B>)
fn bitand_assign(&mut self, rhs: Weight<B>)
&=
operation. Read moreSource§impl<A, B> BitOrAssign<Weight<B>> for &mut Weight<A>where
A: BitOrAssign<B>,
impl<A, B> BitOrAssign<Weight<B>> for &mut Weight<A>where
A: BitOrAssign<B>,
Source§fn bitor_assign(&mut self, rhs: Weight<B>)
fn bitor_assign(&mut self, rhs: Weight<B>)
|=
operation. Read moreSource§impl<A, B> BitOrAssign<Weight<B>> for Weight<A>where
A: BitOrAssign<B>,
impl<A, B> BitOrAssign<Weight<B>> for Weight<A>where
A: BitOrAssign<B>,
Source§fn bitor_assign(&mut self, rhs: Weight<B>)
fn bitor_assign(&mut self, rhs: Weight<B>)
|=
operation. Read moreSource§impl<A, B> BitXorAssign<Weight<B>> for &mut Weight<A>where
A: BitXorAssign<B>,
impl<A, B> BitXorAssign<Weight<B>> for &mut Weight<A>where
A: BitXorAssign<B>,
Source§fn bitxor_assign(&mut self, rhs: Weight<B>)
fn bitxor_assign(&mut self, rhs: Weight<B>)
^=
operation. Read moreSource§impl<A, B> BitXorAssign<Weight<B>> for Weight<A>where
A: BitXorAssign<B>,
impl<A, B> BitXorAssign<Weight<B>> for Weight<A>where
A: BitXorAssign<B>,
Source§fn bitxor_assign(&mut self, rhs: Weight<B>)
fn bitxor_assign(&mut self, rhs: Weight<B>)
^=
operation. Read moreSource§impl<T> BorrowMut<T> for Weight<T>
impl<T> BorrowMut<T> for Weight<T>
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, Idx> BorrowMut<Weight<T>> for Node<T, Idx>where
Idx: RawIndex,
impl<T, Idx> BorrowMut<Weight<T>> for Node<T, Idx>where
Idx: RawIndex,
Source§fn borrow_mut(&mut self) -> &mut Weight<T>
fn borrow_mut(&mut self) -> &mut Weight<T>
Source§impl<'de, T> Deserialize<'de> for Weight<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Weight<T>where
T: Deserialize<'de>,
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<A, B> DivAssign<Weight<B>> for &mut Weight<A>where
A: DivAssign<B>,
impl<A, B> DivAssign<Weight<B>> for &mut Weight<A>where
A: DivAssign<B>,
Source§fn div_assign(&mut self, rhs: Weight<B>)
fn div_assign(&mut self, rhs: Weight<B>)
/=
operation. Read moreSource§impl<A, B> DivAssign<Weight<B>> for Weight<A>where
A: DivAssign<B>,
impl<A, B> DivAssign<Weight<B>> for Weight<A>where
A: DivAssign<B>,
Source§fn div_assign(&mut self, rhs: Weight<B>)
fn div_assign(&mut self, rhs: Weight<B>)
/=
operation. Read moreSource§impl<A, B> MulAssign<Weight<B>> for &mut Weight<A>where
A: MulAssign<B>,
impl<A, B> MulAssign<Weight<B>> for &mut Weight<A>where
A: MulAssign<B>,
Source§fn mul_assign(&mut self, rhs: Weight<B>)
fn mul_assign(&mut self, rhs: Weight<B>)
*=
operation. Read moreSource§impl<A, B> MulAssign<Weight<B>> for Weight<A>where
A: MulAssign<B>,
impl<A, B> MulAssign<Weight<B>> for Weight<A>where
A: MulAssign<B>,
Source§fn mul_assign(&mut self, rhs: Weight<B>)
fn mul_assign(&mut self, rhs: Weight<B>)
*=
operation. Read moreSource§impl<T> Num for Weight<T>where
T: Num,
impl<T> Num for Weight<T>where
T: Num,
type FromStrRadixErr = <T as Num>::FromStrRadixErr
Source§fn from_str_radix(s: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(s: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
2..=36
). Read moreSource§impl<T: Ord> Ord for Weight<T>
impl<T: Ord> Ord for Weight<T>
Source§impl<T> PartialOrd<T> for Weight<T>where
T: PartialOrd,
impl<T> PartialOrd<T> for Weight<T>where
T: PartialOrd,
Source§impl<T: PartialOrd> PartialOrd for Weight<T>
impl<T: PartialOrd> PartialOrd for Weight<T>
Source§impl<A, B> RemAssign<Weight<B>> for &mut Weight<A>where
A: RemAssign<B>,
impl<A, B> RemAssign<Weight<B>> for &mut Weight<A>where
A: RemAssign<B>,
Source§fn rem_assign(&mut self, rhs: Weight<B>)
fn rem_assign(&mut self, rhs: Weight<B>)
%=
operation. Read moreSource§impl<A, B> RemAssign<Weight<B>> for Weight<A>where
A: RemAssign<B>,
impl<A, B> RemAssign<Weight<B>> for Weight<A>where
A: RemAssign<B>,
Source§fn rem_assign(&mut self, rhs: Weight<B>)
fn rem_assign(&mut self, rhs: Weight<B>)
%=
operation. Read moreSource§impl<A, B> ShlAssign<Weight<B>> for &mut Weight<A>where
A: ShlAssign<B>,
impl<A, B> ShlAssign<Weight<B>> for &mut Weight<A>where
A: ShlAssign<B>,
Source§fn shl_assign(&mut self, rhs: Weight<B>)
fn shl_assign(&mut self, rhs: Weight<B>)
<<=
operation. Read moreSource§impl<A, B> ShlAssign<Weight<B>> for Weight<A>where
A: ShlAssign<B>,
impl<A, B> ShlAssign<Weight<B>> for Weight<A>where
A: ShlAssign<B>,
Source§fn shl_assign(&mut self, rhs: Weight<B>)
fn shl_assign(&mut self, rhs: Weight<B>)
<<=
operation. Read moreSource§impl<A, B> ShrAssign<Weight<B>> for &mut Weight<A>where
A: ShrAssign<B>,
impl<A, B> ShrAssign<Weight<B>> for &mut Weight<A>where
A: ShrAssign<B>,
Source§fn shr_assign(&mut self, rhs: Weight<B>)
fn shr_assign(&mut self, rhs: Weight<B>)
>>=
operation. Read moreSource§impl<A, B> ShrAssign<Weight<B>> for Weight<A>where
A: ShrAssign<B>,
impl<A, B> ShrAssign<Weight<B>> for Weight<A>where
A: ShrAssign<B>,
Source§fn shr_assign(&mut self, rhs: Weight<B>)
fn shr_assign(&mut self, rhs: Weight<B>)
>>=
operation. Read moreSource§impl<A, B> SubAssign<Weight<B>> for &mut Weight<A>where
A: SubAssign<B>,
impl<A, B> SubAssign<Weight<B>> for &mut Weight<A>where
A: SubAssign<B>,
Source§fn sub_assign(&mut self, rhs: Weight<B>)
fn sub_assign(&mut self, rhs: Weight<B>)
-=
operation. Read moreSource§impl<A, B> SubAssign<Weight<B>> for Weight<A>where
A: SubAssign<B>,
impl<A, B> SubAssign<Weight<B>> for Weight<A>where
A: SubAssign<B>,
Source§fn sub_assign(&mut self, rhs: Weight<B>)
fn sub_assign(&mut self, rhs: Weight<B>)
-=
operation. Read moreimpl<T: Copy> Copy for Weight<T>
impl<T: Eq> Eq for Weight<T>
impl<T> StructuralPartialEq for Weight<T>
Auto Trait Implementations§
impl<T> Freeze for Weight<T>where
T: Freeze,
impl<T> RefUnwindSafe for Weight<T>where
T: RefUnwindSafe,
impl<T> Send for Weight<T>where
T: Send,
impl<T> Sync for Weight<T>where
T: Sync,
impl<T> Unpin for Weight<T>where
T: Unpin,
impl<T> UnwindSafe for Weight<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> AsWeight<T> for Twhere
T: Clone + IntoWeight<T>,
impl<T> AsWeight<T> for Twhere
T: Clone + IntoWeight<T>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<K, S> Identity<K> for Swhere
S: Borrow<K>,
K: Identifier,
impl<K, S> Identity<K> for Swhere
S: Borrow<K>,
K: Identifier,
Source§impl<T> IntoWeight<T> for T
impl<T> IntoWeight<T> for T
fn into_weight(self) -> Weight<T>
Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
StandardUniform
distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
p
of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator
of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
random
to avoid conflict with the new gen
keyword in Rust 2024.Rng::random
.Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
random_range
Rng::random_range
.Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
u32
.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
u64
.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
dest
entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
UnwrapMut
wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
RngCore
to a RngReadAdapter
.