pub struct Probability(/* private fields */);Expand description
A probability in the closed unit interval [0, 1], valid by construction.
A Probability can never hold a NaN, an infinity, a negative, or a value
above one: every constructor enforces 0.0 <= p <= 1.0 (a NaN/Inf fails
the comparison). As a result the silent all-false-mask degeneracy of
u.lower_elem(p) / rng < p on a bad rate is unrepresentable wherever a
Probability is held.
Construct with new for literals (panics on an invalid value)
or try_new for runtime data (returns ProbabilityError).
Deserialize routes through try_new via TryFrom, so a rate loaded
from a file cannot deserialize into an out-of-range Probability.
Implementations§
Source§impl Probability
impl Probability
Sourcepub const fn new(p: f32) -> Self
pub const fn new(p: f32) -> Self
Builds a probability from a compile-time-known value, panicking on an invalid one.
This is the constructor for literals and Defaults — the bad value is
right at the call site, mirroring the documented builder-setter panic
exception of ADR 0026. Prefer try_new for any value
derived from runtime or user-supplied data.
§Panics
Panics when p is outside [0, 1] (including NaN or infinite).
Sourcepub fn try_new(p: f32) -> Result<Self, ProbabilityError>
pub fn try_new(p: f32) -> Result<Self, ProbabilityError>
Builds a probability from a runtime / user-supplied value.
§Errors
Returns ProbabilityError when p is outside [0, 1] (including
NaN or infinite).
Trait Implementations§
Source§impl Clone for Probability
impl Clone for Probability
Source§fn clone(&self) -> Probability
fn clone(&self) -> Probability
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for Probability
Source§impl Debug for Probability
impl Debug for Probability
Source§impl<'de> Deserialize<'de> for Probability
impl<'de> Deserialize<'de> for Probability
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 From<Probability> for f32
impl From<Probability> for f32
Source§fn from(p: Probability) -> Self
fn from(p: Probability) -> Self
Source§impl PartialEq for Probability
impl PartialEq for Probability
Source§impl Serialize for Probability
impl Serialize for Probability
impl StructuralPartialEq for Probability
Auto Trait Implementations§
impl Freeze for Probability
impl RefUnwindSafe for Probability
impl Send for Probability
impl Sync for Probability
impl Unpin for Probability
impl UnsafeUnpin for Probability
impl UnwindSafe for Probability
Blanket Implementations§
impl<T> Boilerplate for 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<C> CloneExpand for Cwhere
C: Clone,
impl<C> CloneExpand for Cwhere
C: Clone,
fn __expand_clone_method(&self, _scope: &mut Scope) -> C
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more