[−][src]Struct probability_to_friendly_string::FriendlyProbability
A probability that can be expressed in a user-friendly form.
The friendly_string
property is a textual representation of
the probability (i.e. "5 out of 7")
Implementations
impl FriendlyProbability
[src]
pub fn new<T: Into<Option<String>>>(
numerator: u8,
denominator: u8,
friendly_description: &'static str,
friendly_string: T
) -> FriendlyProbability
[src]
numerator: u8,
denominator: u8,
friendly_description: &'static str,
friendly_string: T
) -> FriendlyProbability
Create a new FriendlyProbability. Most of the time you will want to use from_probability()
instead.
pub fn numerator(self: &FriendlyProbability) -> u8
[src]
Gets the numerator of the FriendlyProbability.
pub fn denominator(self: &FriendlyProbability) -> u8
[src]
Gets the denominator of the FriendlyProbability.
pub fn friendly_description(self: &FriendlyProbability) -> &str
[src]
Gets the friendly description of the FriendlyProbability. This is a qualitative description of the probability ("Still possible", "Flip a coin", "Good chance", etc.)
pub fn friendly_string(self: &FriendlyProbability) -> &str
[src]
Gets the friendly string of the FriendlyProbability. Usually this is the same as "{numerator} in {denominator}", but if the probability is very small it will instead be "<1 in 100", and if it's very large it will be ">99 in 100"
pub fn from_probability(probability: f32) -> FriendlyProbability
[src]
Create a FriendlyProbability from an f32.
Examples
use probability_to_friendly_string::FriendlyProbability; let friendly = FriendlyProbability::from_probability(0.723); assert_eq!(5, friendly.numerator()); assert_eq!(7, friendly.denominator()); assert_eq!("Good chance", friendly.friendly_description()); assert_eq!("5 in 7", friendly.friendly_string()); let friendly = FriendlyProbability::from_probability(0.999); assert_eq!(">99 in 100", friendly.friendly_string()); let friendly = FriendlyProbability::from_probability(0.001); assert_eq!("<1 in 100", friendly.friendly_string());
Panics
If probability is less than 0.0 or greater than 1.0.
Trait Implementations
impl Debug for FriendlyProbability
[src]
impl Display for FriendlyProbability
[src]
impl Eq for FriendlyProbability
[src]
impl PartialEq<FriendlyProbability> for FriendlyProbability
[src]
fn eq(&self, other: &FriendlyProbability) -> bool
[src]
fn ne(&self, other: &FriendlyProbability) -> bool
[src]
impl StructuralEq for FriendlyProbability
[src]
impl StructuralPartialEq for FriendlyProbability
[src]
Auto Trait Implementations
impl RefUnwindSafe for FriendlyProbability
impl Send for FriendlyProbability
impl Sync for FriendlyProbability
impl Unpin for FriendlyProbability
impl UnwindSafe for FriendlyProbability
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,