pub struct QValue(/* private fields */);Expand description
A quality value: 0 to 1 in thousandths (RFC 9110 section 12.4.2). No floating point.
§Examples
use parse_net::QValue;
assert_eq!(QValue::parse(b"0.5")?.thousandths(), 500);
assert_eq!(QValue::parse(b"1.000")?, QValue::ONE);
assert!(QValue::parse(b"1.5").is_err() && QValue::parse(b".5").is_err());Implementations§
Source§impl QValue
impl QValue
Sourcepub const ONE: Self
pub const ONE: Self
q=1, the weight of a member without q.
§Examples
use parse_net::QValue;
assert_eq!(QValue::ONE.thousandths(), 1000);
assert_eq!(QValue::parse(b"1")?, QValue::ONE);Sourcepub const ZERO: Self
pub const ZERO: Self
q=0: not acceptable.
§Examples
use parse_net::QValue;
assert_eq!(QValue::parse(b"0.000")?, QValue::ZERO);
assert!(QValue::ZERO < QValue::ONE);Sourcepub const fn from_thousandths(t: u16) -> Option<Self>
pub const fn from_thousandths(t: u16) -> Option<Self>
The weight t thousandths, if t is at most 1000.
§Examples
use parse_net::QValue;
assert_eq!(QValue::from_thousandths(500), Some(QValue::parse(b"0.5")?));
assert_eq!(QValue::from_thousandths(1001), None);Sourcepub const fn thousandths(self) -> u16
pub const fn thousandths(self) -> u16
The weight in thousandths, 0 to 1000.
§Examples
assert_eq!(parse_net::QValue::parse(b"0.05")?.thousandths(), 50);Sourcepub fn parse(s: &[u8]) -> Result<Self, ParseError>
pub fn parse(s: &[u8]) -> Result<Self, ParseError>
Parses ( "0" [ "." 0*3DIGIT ] ) / ( "1" [ "." 0*3("0") ] ).
§Errors
ErrorKind::InvalidQValue for anything else (1.5, 0.1234, .5,
-1, 1.001, an empty value).
§Examples
use parse_net::QValue;
assert_eq!(QValue::parse(b"0.125")?.thousandths(), 125);
assert!(QValue::parse(b"0.1234").is_err());Trait Implementations§
impl Copy for QValue
impl Eq for QValue
Source§impl Ord for QValue
impl Ord for QValue
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
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for QValue
impl PartialOrd for QValue
impl StructuralPartialEq for QValue
Auto Trait Implementations§
impl Forget for QValue
impl Freeze for QValue
impl RefUnwindSafe for QValue
impl Send for QValue
impl Sync for QValue
impl Unpin for QValue
impl UnsafeUnpin for QValue
impl UnwindSafe for QValue
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