clippy my beloved

This commit is contained in:
Freya Murphy 2023-06-08 00:58:29 -04:00
parent 2dad06cae3
commit 665e500fe7
3 changed files with 31 additions and 31 deletions

View file

@ -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")
}
}
}

View file

@ -1,9 +1,26 @@
use std::cell::RefCell; use std::cell::RefCell;
use libc::malloc; use libc::malloc;
use std::fmt::{Result, Display, Formatter};
pub mod error;
pub mod parse; 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)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct PissAmount { pub struct PissAmount {
to_piss: u128 to_piss: u128

View file

@ -1,10 +1,10 @@
use std::str::FromStr; use std::str::FromStr;
use crate::{error::PissError, PissAmount}; use crate::{PissError, PissAmount};
impl<T> From<T> for PissAmount impl<T> From<T> for PissAmount
where T: Into<u128> { where T: Into<u128> {
fn from(num: T) -> PissAmount { fn from(num: T) -> Self {
PissAmount { Self {
to_piss: num.into() 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, "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, "q" | "qb" => 1_000_000_000_000_000_000_000_000_000_000,
"ki" | "kib" => 0x400, "ki" | "kib" => 0x400,
"mi" | "mib" => 0x100000, "mi" | "mib" => 0x0010_0000,
"gi" | "gib" => 0x40000000, "gi" | "gib" => 0x4000_0000,
"ti" | "tib" => 0x10000000000, "ti" | "tib" => 0x0100_0000_0000,
"pi" | "pib" => 0x4000000000000, "pi" | "pib" => 0x0004_0000_0000_0000,
"ei" | "eib" => 0x1000000000000000, "ei" | "eib" => 0x1000_0000_0000_0000,
"xi" | "xib" => 0x400000000000000000, "xi" | "xib" => 0x0040_0000_0000_0000_0000,
"yi" | "yib" => 0x100000000000000000000, "yi" | "yib" => 0x0001_0000_0000_0000_0000_0000,
"ri" | "rib" => 0x40000000000000000000000, "ri" | "rib" => 0x0400_0000_0000_0000_0000_0000,
"qi" | "qib" => 0x10000000000000000000000000, "qi" | "qib" => 0x0010_0000_0000_0000_0000_0000_0000,
"" | "b" => 1, // uwu "" | "b" => 1, // uwu
_ => return Err(PissError::InvalidSuffix(s.into())) // such nepal _ => 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> { fn parse_file_size(s: &str) -> Result<PissAmount, PissError> {
let mut end = 0; let mut end = 0;
for (i, c) in s.char_indices() { for (i, c) in s.char_indices() {
if c.is_digit(10) || c == '.' { continue; } if c.is_ascii_digit() || c == '.' { continue; }
end = i; end = i;
break; break;
} }