diff options
Diffstat (limited to 'crates/bytes/src')
-rw-r--r-- | crates/bytes/src/error.rs | 5 | ||||
-rw-r--r-- | crates/bytes/src/lib.rs | 11 |
2 files changed, 13 insertions, 3 deletions
diff --git a/crates/bytes/src/error.rs b/crates/bytes/src/error.rs index 7643109..c9783d8 100644 --- a/crates/bytes/src/error.rs +++ b/crates/bytes/src/error.rs @@ -11,6 +11,7 @@ use std::{fmt::Display, num::ParseIntError}; #[derive(Debug)] +#[allow(clippy::module_name_repetitions)] pub enum BytesError { BytesParseIntError(ParseIntError), NotYetSupported(String), @@ -20,10 +21,10 @@ impl Display for BytesError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { BytesError::BytesParseIntError(e) => { - f.write_fmt(format_args!("Failed to parse a number as integer: '{}'", e)) + f.write_fmt(format_args!("Failed to parse a number as integer: '{e}'")) }, BytesError::NotYetSupported(other) => { - f.write_fmt(format_args!("Your extension '{}' is not yet supported. Only KB,MB,GB or KiB,MiB,GiB are supported", other)) + f.write_fmt(format_args!("Your extension '{other}' is not yet supported. Only KB,MB,GB or KiB,MiB,GiB are supported")) } } } diff --git a/crates/bytes/src/lib.rs b/crates/bytes/src/lib.rs index 78d3c4e..6e3f73c 100644 --- a/crates/bytes/src/lib.rs +++ b/crates/bytes/src/lib.rs @@ -8,6 +8,12 @@ // You should have received a copy of the License along with this program. // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. +#![allow( + clippy::cast_possible_truncation, + clippy::cast_precision_loss, + clippy::cast_sign_loss, + clippy::cast_possible_wrap +)] use std::{fmt::Display, str::FromStr}; use error::BytesError; @@ -28,13 +34,15 @@ const TB: u64 = 1000 * GB; pub mod error; pub mod serde; -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] pub struct Bytes(u64); impl Bytes { + #[must_use] pub fn as_u64(self) -> u64 { self.0 } + #[must_use] pub fn new(v: u64) -> Self { Self(v) } @@ -140,6 +148,7 @@ impl Display for Bytes { /// assert_eq!(precision_f64(1.2300_f32 as f64, 2) as f32, 1.2f32); ///# } /// ``` +#[must_use] pub fn precision_f64(x: f64, decimals: u32) -> f64 { if x == 0. || decimals == 0 { 0. |