Skip to content

Commit

Permalink
fix(clippy): x5
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Jul 31, 2023
1 parent 8d95ebf commit 04279d2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
4 changes: 4 additions & 0 deletions viz-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ impl Error {
}

/// Attempt to downcast the error object to a concrete type.
///
/// # Errors
///
/// Throws an `Error` if downcast fails.
#[inline]
pub fn downcast<T>(self) -> Result<T, Self>
where
Expand Down
6 changes: 5 additions & 1 deletion viz-core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ pub trait ResponseExt: Sized {
Self::with(t, mime::TEXT_HTML_UTF_8.as_ref())
}

#[cfg(feature = "json")]
/// The response with `application/javascript; charset=utf-8` media type.
///
/// # Errors
///
/// Throws an error if serialization fails.
#[cfg(feature = "json")]
fn json<T>(t: T) -> Result<Response, crate::types::PayloadError>
where
T: serde::Serialize,
Expand Down
6 changes: 4 additions & 2 deletions viz-core/src/types/params/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ impl<'de> de::VariantAccess<'de> for UnitVariant {
}
}

#[allow(clippy::items_after_statements)]
#[cfg(test)]
mod tests {
use serde::de;
Expand Down Expand Up @@ -539,6 +540,7 @@ mod tests {
};
}

#[allow(clippy::float_cmp)]
#[test]
fn test_parse_single_value() {
check_single_value!(bool, "true", true);
Expand All @@ -551,8 +553,8 @@ mod tests {
check_single_value!(u16, "123", 123);
check_single_value!(u32, "123", 123);
check_single_value!(u64, "123", 123);
check_single_value!(f32, "123", 123.0);
check_single_value!(f64, "123", 123.0);
check_single_value!(f32, "123", 123f32);
check_single_value!(f64, "123", 123f64);
check_single_value!(String, "abc", "abc");
check_single_value!(String, "one%20two", "one%20two");
check_single_value!(&str, "abc", "abc");
Expand Down
28 changes: 14 additions & 14 deletions viz-core/src/types/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,26 @@ pub trait Payload {
}

/// Checks `Content-Type` & `Content-Length`
///
/// # Errors
///
/// 1. unsupported media type
/// 2. content-length is required
/// 3. payload is too large
#[inline]
fn check_header(
m: Option<mime::Mime>,
len: Option<u64>,
limit: Option<u64>,
) -> Result<mime::Mime, PayloadError> {
let m = m.ok_or_else(|| PayloadError::UnsupportedMediaType(Self::mime()))?;

if !Self::detect(&m) {
return Err(PayloadError::UnsupportedMediaType(Self::mime()));
}

if len.is_none() {
return Err(PayloadError::LengthRequired);
let m = m
.filter(Self::detect)
.ok_or_else(|| PayloadError::UnsupportedMediaType(Self::mime()))?;

match len {
None => Err(PayloadError::LengthRequired),
Some(len) if len > Self::limit(limit) => Err(PayloadError::TooLarge),
Some(_) => Ok(m),
}

if matches!(len, Some(len) if len > Self::limit(limit)) {
return Err(PayloadError::TooLarge);
}

Ok(m)
}
}

0 comments on commit 04279d2

Please sign in to comment.