Skip to content

Commit

Permalink
release: 0.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstoik1 committed Sep 15, 2024
2 parents df894d4 + 750f3a8 commit f1b8e7a
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@



## [0.7.4](https://github.com/Blobfolio/dactyl/releases/tag/v0.7.4) - 2024-09-15

### New

* Add explicit `len` and `is_empty` methods to `NiceWrapper` to avoid deref.



## [0.7.3](https://github.com/Blobfolio/dactyl/releases/tag/v0.7.3) - 2024-09-05

### Changed
Expand Down
4 changes: 2 additions & 2 deletions CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Project Dependencies
Package: dactyl
Version: 0.7.3
Generated: 2024-09-05 19:01:43 UTC
Version: 0.7.4
Generated: 2024-09-15 08:15:40 UTC

This package has no dependencies.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dactyl"
version = "0.7.3"
version = "0.7.4"
authors = ["Blobfolio, LLC. <[email protected]>"]
edition = "2021"
rust-version = "1.70"
Expand Down
8 changes: 8 additions & 0 deletions src/nice_int/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ impl<const S: usize> NiceWrapper<S> {
// Safety: numbers are valid ASCII.
unsafe { std::str::from_utf8_unchecked(self.as_bytes()) }
}

#[must_use]
/// # Is Empty?
pub const fn is_empty(&self) -> bool { S <= self.from }

#[must_use]
/// # Length.
pub const fn len(&self) -> usize { S.wrapping_sub(self.from) }
}


Expand Down
10 changes: 10 additions & 0 deletions src/nice_int/nice_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,16 @@ const fn round_tie_even(offset: u128, tmp: u128) -> u32 {
mod tests {
use super::*;

#[test]
fn t_len() {
for i in [0_f64, 1.1, 1.55, 123.456, -11_323.03] {
let nice = NiceFloat::from(i);
assert_eq!(nice.len(), nice.as_str().len());
assert_eq!(nice.len(), nice.as_bytes().len());
assert!(! nice.is_empty());
}
}

#[test]
fn t_nice_float() {
// Some basic numbers.
Expand Down
12 changes: 10 additions & 2 deletions src/nice_int/nice_percent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,26 @@ mod tests {
macro_rules! t_str {
($var:ident) => (
let fraction = $var as f32 / TOTAL as f32;
let nice = NicePercent::from(fraction);
assert_eq!(
NicePercent::from(fraction).as_str(),
nice.as_str(),
format!("{:0.02}%", fraction * 100_f32),
"{}/{} (f32)", $var, TOTAL
);
assert_eq!(nice.len(), nice.as_str().len());
assert_eq!(nice.len(), nice.as_bytes().len());
assert!(! nice.is_empty());

let fraction = $var as f64 / TOTAL as f64;
let nice = NicePercent::from(fraction);
assert_eq!(
NicePercent::from(fraction).as_str(),
nice.as_str(),
format!("{:0.02}%", fraction * 100_f64),
"{}/{} (f64)", $var, TOTAL
);
assert_eq!(nice.len(), nice.as_str().len());
assert_eq!(nice.len(), nice.as_bytes().len());
assert!(! nice.is_empty());
);
}

Expand Down
13 changes: 11 additions & 2 deletions src/nice_int/nice_u16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,35 @@ mod tests {

#[cfg(not(miri))]
for i in 0..=u16::MAX {
let nice = NiceU16::from(i);
assert_eq!(
NiceU16::from(i).as_str(),
nice.as_str(),
i.to_formatted_string(&Locale::en),
);
assert_eq!(nice.len(), nice.as_str().len());
assert_eq!(nice.len(), nice.as_bytes().len());
assert!(! nice.is_empty());
}

#[cfg(miri)]
{
let mut rng = fastrand::Rng::new();
for i in std::iter::repeat_with(|| rng.u16(..)).take(1000) {
let nice = NiceU16::from(i);
assert_eq!(
NiceU16::from(i).as_str(),
nice.as_str(),
i.to_formatted_string(&Locale::en),
);
assert_eq!(nice.len(), nice.as_str().len());
assert_eq!(nice.len(), nice.as_bytes().len());
assert!(! nice.is_empty());
}
}

// Test the defaults too.
assert_eq!(NiceU16::empty().as_bytes(), <&[u8]>::default());
assert_eq!(NiceU16::empty().as_str(), "");
assert!(NiceU16::empty().is_empty());

// Test some Option variants.
let foo: Option<u16> = None;
Expand Down
7 changes: 6 additions & 1 deletion src/nice_int/nice_u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ mod tests {
// Test the defaults too.
assert_eq!(NiceU32::empty().as_bytes(), <&[u8]>::default());
assert_eq!(NiceU32::empty().as_str(), "");
assert!(NiceU32::empty().is_empty());

// Check ordering too.
let one = NiceU32::from(10_u32);
Expand All @@ -144,10 +145,14 @@ mod tests {
// Check a subset of everything else.
let mut rng = fastrand::Rng::new();
for i in std::iter::repeat_with(|| rng.u32(..)).take(SAMPLE_SIZE) {
let nice = NiceU32::from(i);
assert_eq!(
NiceU32::from(i).as_str(),
nice.as_str(),
i.to_formatted_string(&Locale::en),
);
assert_eq!(nice.len(), nice.as_str().len());
assert_eq!(nice.len(), nice.as_bytes().len());
assert!(! nice.is_empty());
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/nice_int/nice_u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ mod tests {
// Test the defaults too.
assert_eq!(NiceU64::empty().as_bytes(), <&[u8]>::default());
assert_eq!(NiceU64::empty().as_str(), "");
assert!(NiceU64::empty().is_empty());

// Test some Option variants.
let foo: Option<u64> = None;
Expand All @@ -164,10 +165,14 @@ mod tests {
// Check a subset of everything else.
let mut rng = fastrand::Rng::new();
for i in std::iter::repeat_with(|| rng.u64(..)).take(SAMPLE_SIZE) {
let nice = NiceU64::from(i);
assert_eq!(
NiceU64::from(i).as_str(),
nice.as_str(),
i.to_formatted_string(&Locale::en),
);
assert_eq!(nice.len(), nice.as_str().len());
assert_eq!(nice.len(), nice.as_bytes().len());
assert!(! nice.is_empty());
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/nice_int/nice_u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,20 @@ mod tests {

// Strings come from bytes, so this implicitly tests both.
for i in 0..=u8::MAX {
let nice = NiceU8::from(i);
assert_eq!(
NiceU8::from(i).as_str(),
nice.as_str(),
format!("{i}"),
);
assert_eq!(nice.len(), nice.as_str().len());
assert_eq!(nice.len(), nice.as_bytes().len());
assert!(! nice.is_empty());
}

// Test the defaults too.
assert_eq!(NiceU8::empty().as_bytes(), <&[u8]>::default());
assert_eq!(NiceU8::empty().as_str(), "");
assert!(NiceU8::empty().is_empty());

// Test some Option variants.
let foo: Option<u8> = None;
Expand Down

0 comments on commit f1b8e7a

Please sign in to comment.