From 665e500fe706c190a9393171fd15eeadfe24c0ed Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Thu, 8 Jun 2023 00:58:29 -0400 Subject: [PATCH] clippy my beloved --- src/error.rs | 17 ----------------- src/lib.rs | 19 ++++++++++++++++++- src/parse.rs | 26 +++++++++++++------------- 3 files changed, 31 insertions(+), 31 deletions(-) delete mode 100644 src/error.rs diff --git a/src/error.rs b/src/error.rs deleted file mode 100644 index 399eb33..0000000 --- a/src/error.rs +++ /dev/null @@ -1,17 +0,0 @@ -use std::fmt::{Result, Display, Formatter}; - -pub enum PissError { - InvalidSuffix(String), - InvalidNumber(String), - NumberNotPositive -} - -impl Display for PissError { - fn fmt(&self, f: &mut Formatter<'_>) -> Result { - match self { - Self::InvalidSuffix(s) => write!(f, "I cannot piss the suffix {s:?}"), - Self::InvalidNumber(s) => write!(f, "I cannot piss the invalid number {s:?}"), - Self::NumberNotPositive => write!(f, "I cannot piss nonexistent memory") - } - } -} diff --git a/src/lib.rs b/src/lib.rs index ebf3274..2b5e3ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,26 @@ use std::cell::RefCell; use libc::malloc; +use std::fmt::{Result, Display, Formatter}; -pub mod error; pub mod parse; +#[derive(Clone, Debug)] +pub enum PissError { + InvalidSuffix(String), + InvalidNumber(String), + NumberNotPositive +} + +impl Display for PissError { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + match self { + Self::InvalidSuffix(s) => write!(f, "I cannot piss the suffix {s:?}"), + Self::InvalidNumber(s) => write!(f, "I cannot piss the invalid number {s:?}"), + Self::NumberNotPositive => write!(f, "I cannot piss nonexistent memory") + } + } +} + #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] pub struct PissAmount { to_piss: u128 diff --git a/src/parse.rs b/src/parse.rs index edfd9c5..c5521d6 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -1,10 +1,10 @@ use std::str::FromStr; -use crate::{error::PissError, PissAmount}; +use crate::{PissError, PissAmount}; impl From for PissAmount where T: Into { - fn from(num: T) -> PissAmount { - PissAmount { + fn from(num: T) -> Self { + Self { to_piss: num.into() } } @@ -23,15 +23,15 @@ fn parse_suffix(s: &str) -> Result { "r" | "rb" => 1_000_000_000_000_000_000_000_000_000, "q" | "qb" => 1_000_000_000_000_000_000_000_000_000_000, "ki" | "kib" => 0x400, - "mi" | "mib" => 0x100000, - "gi" | "gib" => 0x40000000, - "ti" | "tib" => 0x10000000000, - "pi" | "pib" => 0x4000000000000, - "ei" | "eib" => 0x1000000000000000, - "xi" | "xib" => 0x400000000000000000, - "yi" | "yib" => 0x100000000000000000000, - "ri" | "rib" => 0x40000000000000000000000, - "qi" | "qib" => 0x10000000000000000000000000, + "mi" | "mib" => 0x0010_0000, + "gi" | "gib" => 0x4000_0000, + "ti" | "tib" => 0x0100_0000_0000, + "pi" | "pib" => 0x0004_0000_0000_0000, + "ei" | "eib" => 0x1000_0000_0000_0000, + "xi" | "xib" => 0x0040_0000_0000_0000_0000, + "yi" | "yib" => 0x0001_0000_0000_0000_0000_0000, + "ri" | "rib" => 0x0400_0000_0000_0000_0000_0000, + "qi" | "qib" => 0x0010_0000_0000_0000_0000_0000_0000, "" | "b" => 1, // uwu _ => return Err(PissError::InvalidSuffix(s.into())) // such nepal }) @@ -40,7 +40,7 @@ fn parse_suffix(s: &str) -> Result { fn parse_file_size(s: &str) -> Result { let mut end = 0; for (i, c) in s.char_indices() { - if c.is_digit(10) || c == '.' { continue; } + if c.is_ascii_digit() || c == '.' { continue; } end = i; break; }