inline quality tryfrom

This commit is contained in:
Rob Ede 2021-12-05 02:58:27 +00:00
parent 134b690364
commit 3e9535a052
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
1 changed files with 3 additions and 1 deletions

View File

@ -47,7 +47,7 @@ impl Quality {
/// ///
/// # Panics /// # Panics
/// Panics in debug mode when value is not in the range 0.0 <= n <= 1.0. /// Panics in debug mode when value is not in the range 0.0 <= n <= 1.0.
pub(super) fn from_f32(value: f32) -> Self { fn from_f32(value: f32) -> Self {
// Check that `value` is within range should be done before calling this method. // Check that `value` is within range should be done before calling this method.
// Just in case, this debug_assert should catch if we were forgetful. // Just in case, this debug_assert should catch if we were forgetful.
debug_assert!( debug_assert!(
@ -118,6 +118,7 @@ pub struct QualityOutOfBounds;
impl TryFrom<f32> for Quality { impl TryFrom<f32> for Quality {
type Error = QualityOutOfBounds; type Error = QualityOutOfBounds;
#[inline]
fn try_from(value: f32) -> Result<Self, Self::Error> { fn try_from(value: f32) -> Result<Self, Self::Error> {
if (0.0..=MAX_QUALITY_FLOAT).contains(&value) { if (0.0..=MAX_QUALITY_FLOAT).contains(&value) {
Ok(Quality::from_f32(value)) Ok(Quality::from_f32(value))
@ -151,6 +152,7 @@ impl TryFrom<f32> for Quality {
/// # use actix_http::header::q; /// # use actix_http::header::q;
/// let _q2 = q(1.42); /// let _q2 = q(1.42);
/// ``` /// ```
#[inline]
pub fn q<T>(quality: T) -> Quality pub fn q<T>(quality: T) -> Quality
where where
T: TryInto<Quality>, T: TryInto<Quality>,