pub struct Percent(/* private fields */);Expand description
Percentage value from 0 to 100 inclusive.
Implementations§
Source§impl Percent
impl Percent
pub const MIN: u8 = 0
pub const MAX: u8 = 100
Sourcepub fn new(value: u8) -> PrimitiveResult<Self>
pub fn new(value: u8) -> PrimitiveResult<Self>
Creates a new percentage value.
Examples found in repository?
examples/primitives_basic.rs (line 8)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 type ServiceName = BoundedStr<3, 32>;
5
6 let display_name = NonEmptyStr::new("Reliakit API")?;
7 let service_name = ServiceName::new("api-service")?;
8 let threshold = Percent::new(95)?;
9 let port = Port::new(8080)?;
10 let body_limit = ByteSize::from_mb(10);
11
12 println!("display name: {display_name}");
13 println!("service name: {service_name}");
14 println!("threshold: {threshold}");
15 println!("port: {port}");
16 println!("body limit: {body_limit}");
17
18 Ok(())
19}Sourcepub fn as_fraction(self) -> f64
pub fn as_fraction(self) -> f64
Returns the percentage as a fraction between 0.0 and 1.0.
Trait Implementations§
Source§impl Ord for Percent
impl Ord for Percent
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for Percent
impl PartialOrd for Percent
impl Copy for Percent
impl Eq for Percent
impl StructuralPartialEq for Percent
Auto Trait Implementations§
impl Freeze for Percent
impl RefUnwindSafe for Percent
impl Send for Percent
impl Sync for Percent
impl Unpin for Percent
impl UnsafeUnpin for Percent
impl UnwindSafe for Percent
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