diff options
author | Tyler Murphy <tylerm@tylerm.dev> | 2023-06-08 00:58:29 -0400 |
---|---|---|
committer | Tyler Murphy <tylerm@tylerm.dev> | 2023-06-08 00:58:29 -0400 |
commit | 665e500fe706c190a9393171fd15eeadfe24c0ed (patch) | |
tree | 02e44b2c17e0271e932cef2ad17b908d689419c9 /src | |
parent | initial (diff) | |
download | leak_memory-665e500fe706c190a9393171fd15eeadfe24c0ed.tar.gz leak_memory-665e500fe706c190a9393171fd15eeadfe24c0ed.tar.bz2 leak_memory-665e500fe706c190a9393171fd15eeadfe24c0ed.zip |
clippy my beloved
Diffstat (limited to 'src')
-rw-r--r-- | src/error.rs | 17 | ||||
-rw-r--r-- | src/lib.rs | 19 | ||||
-rw-r--r-- | src/parse.rs | 26 |
3 files changed, 31 insertions, 31 deletions
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") - } - } -} @@ -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<T> From<T> for PissAmount where T: Into<u128> { - 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<u128, PissError> { "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<u128, PissError> { fn parse_file_size(s: &str) -> Result<PissAmount, PissError> { 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; } |