Skip to content

Commit

Permalink
Reduce enum size
Browse files Browse the repository at this point in the history
  • Loading branch information
c410-f3r committed Dec 6, 2023
1 parent 77b28d8 commit 770d45d
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions cl-aux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ smallvec = { default-features = false, optional = true, version = "1.0" }
tinyvec = { default-features = false, optional = true, version = "1.0" }

[features]
alloc = []
alloc = ["tinyvec?/alloc"]
default = []
std = ["alloc", "tinyvec?/alloc"]
std = ["alloc"]

[package]
authors = ["Caio Fernandes <[email protected]>"]
Expand Down
8 changes: 4 additions & 4 deletions cl-aux/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ macro_rules! _check_capacity {
let capacity_upper_bound = crate::CapacityUpperBound::capacity_upper_bound($elem);
let length = crate::Length::length($elem);
if length >= capacity_upper_bound {
return Err(crate::Error::InsufficientCapacity(stringify!($elem), capacity_upper_bound));
return Err(crate::Error::InsufficientCapacity(capacity_upper_bound));
}
}};
}
Expand All @@ -12,19 +12,19 @@ macro_rules! _check_indcs {
($elem:expr, $( $idx:expr ),*) => {{
let length = crate::Length::length($elem);
if $( $idx >= length || )* false {
return Err(crate::Error::OutOfBounds(stringify!($elem), length));
return Err(crate::Error::OutOfBounds(length));
}
}};
}

macro_rules! _get {
($elem:expr, $idx:expr) => {{
$elem.get($idx).ok_or(crate::Error::OutOfBounds(stringify!($elem), $idx))
$elem.get($idx).ok_or(crate::Error::OutOfBounds($idx))
}};
}

macro_rules! _get_mut {
($elem:expr, $idx:expr) => {{
$elem.get_mut($idx).ok_or(crate::Error::OutOfBounds(stringify!($elem), $idx))
$elem.get_mut($idx).ok_or(crate::Error::OutOfBounds($idx))
}};
}
6 changes: 3 additions & 3 deletions cl-aux/src/structures/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use core::fmt::{Debug, Display, Formatter};
#[derive(Debug, Eq, PartialEq)]
pub enum Error {
/// It is not possible to insert an already existing element
AlreadyExistingElement(&'static str, &'static str),
AlreadyExistingElement,
/// Structure can't store more elements
InsufficientCapacity(&'static str, usize),
InsufficientCapacity(usize),
/// Index is out of structure bounds
OutOfBounds(&'static str, usize),
OutOfBounds(usize),
}

impl Display for Error {
Expand Down
2 changes: 1 addition & 1 deletion cl-aux/src/traits/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<T> Extend<T> for Option<T> {
#[inline]
fn extend(&mut self, into_iter: impl IntoIterator<Item = T>) -> Result<(), Self::Error> {
_check_capacity!(self);
let err = || crate::Error::InsufficientCapacity(stringify!(self), 1);
let err = || crate::Error::InsufficientCapacity(1);
let mut iter = into_iter.into_iter();
let next = iter.next().ok_or_else(err)?;
*self = Some(next);
Expand Down
6 changes: 3 additions & 3 deletions cl-aux/src/traits/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
macro_rules! _manage_hash {
($hash:expr, $key:expr, $value:expr) => {{
if $hash.contains_key(&$key) {
Err(crate::Error::AlreadyExistingElement(stringify!($hash), stringify!($key)))
Err(crate::Error::AlreadyExistingElement)
} else {
let _maybe_discarded = $hash.insert($key, $value);
Ok(())
Expand All @@ -17,7 +17,7 @@ macro_rules! _manage_hash {
macro_rules! _manage_set {
($set:expr, $value:expr) => {{
if $set.contains(&$value) {
Err(crate::Error::AlreadyExistingElement(stringify!($set), stringify!($value)))
Err(crate::Error::AlreadyExistingElement)
} else {
let _ = $set.insert($value);
Ok(())
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<T> Insert for Option<T> {
#[inline]
fn insert(&mut self, input: Self::Input) -> Result<(), Self::Error> {
if self.is_some() {
Err(crate::Error::InsufficientCapacity(stringify!(self), 1))
Err(crate::Error::InsufficientCapacity(1))
} else {
*self = Some(input);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion cl-aux/src/traits/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<T> Push<T> for Option<T> {
#[inline]
fn push(&mut self, input: T) -> Result<(), Self::Error> {
if self.is_some() {
Err(crate::Error::InsufficientCapacity(stringify!(self), 1))
Err(crate::Error::InsufficientCapacity(1))
} else {
*self = Some(input);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2023-10-11"
channel = "nightly-2023-10-15"
components = ["clippy", "miri", "rustfmt"]
profile = "minimal"
1 change: 1 addition & 0 deletions rust-tools/src/cfg/you_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const CLIPPY_FLAGS: &[&str] = &[
"-Aclippy::unneeded_field_pattern",
"-Aclippy::unseparated_literal_suffix",
"-Aclippy::unused_self",
"-Aclippy::used_underscore_binding",
];

const RUST_FLAGS: &[&str] = &[
Expand Down

0 comments on commit 770d45d

Please sign in to comment.