Function actix_web::http::header::q

source ·
pub fn q<T>(quality: T) -> Quality
where T: TryInto<Quality>, <T as TryInto<Quality>>::Error: Debug,
Expand description

Convenience function to create a Quality from an f32 (0.0–1.0).

Not recommended for use with user input. Rely on the TryFrom impls where possible.

§Panics

Panics if value is out of range.

§Examples

let q1 = q(1.0);
assert_eq!(q1, Quality::MAX);

let q2 = q(0.001);
assert_eq!(q2, Quality::MIN);

let q3 = q(0.0);
assert_eq!(q3, Quality::ZERO);

let q4 = q(0.42);

An out-of-range f32 quality will panic.

let _q2 = q(1.42);