pub struct CopyableWeightedResult<T>{
pub result: T,
pub weight: u32,
}Expand description
A result able to be picked at random in a list of possible results. The weight is used to determine the chances of this result to be picked against all other possible choices. The result must be copyable.
Fields§
§result: TThe result that can be selected at random.
weight: u32The eventual weight of this result. A higher weight means that the result will be more likely to be picked in an uniform distribution.
Or with an example: when using the SimpleRoll RollMethod, an item with a weight of 5 will have 5 more chances to be selected than an item with a weight of one;
Implementations§
Source§impl<T: Copy + Debug> CopyableWeightedResult<T>
impl<T: Copy + Debug> CopyableWeightedResult<T>
Sourcepub fn new(result: T, weight: u32) -> Self
pub fn new(result: T, weight: u32) -> Self
Creates a new CopyableWeightedResult.
Trait Implementations§
Source§impl<T> Clone for CopyableWeightedResult<T>
impl<T> Clone for CopyableWeightedResult<T>
Source§fn clone(&self) -> CopyableWeightedResult<T>
fn clone(&self) -> CopyableWeightedResult<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T> Debug for CopyableWeightedResult<T>
impl<T> Debug for CopyableWeightedResult<T>
Source§impl<T> Default for CopyableWeightedResult<T>
impl<T> Default for CopyableWeightedResult<T>
Source§fn default() -> CopyableWeightedResult<T>
fn default() -> CopyableWeightedResult<T>
Returns the “default value” for a type. Read more
Source§impl<'de, T> Deserialize<'de> for CopyableWeightedResult<T>
impl<'de, T> Deserialize<'de> for CopyableWeightedResult<T>
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T> Serialize for CopyableWeightedResult<T>
impl<T> Serialize for CopyableWeightedResult<T>
impl<T> Copy for CopyableWeightedResult<T>
Auto Trait Implementations§
impl<T> Freeze for CopyableWeightedResult<T>where
T: Freeze,
impl<T> RefUnwindSafe for CopyableWeightedResult<T>where
T: RefUnwindSafe,
impl<T> Send for CopyableWeightedResult<T>where
T: Send,
impl<T> Sync for CopyableWeightedResult<T>where
T: Sync,
impl<T> Unpin for CopyableWeightedResult<T>where
T: Unpin,
impl<T> UnwindSafe for CopyableWeightedResult<T>where
T: UnwindSafe,
Blanket Implementations§
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
Mutably borrows from an owned value. Read more