summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-17 11:32:15 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-17 11:45:57 +0100
commit312197b276748e1a17258ad21837850f582a467c (patch)
tree3fd0c078a2673a98b74bc12b4d654a4c143b4e1f /src/util
parente8435df5ec718e8ecc8a2ad48e4eb3ddd1f92a72 (diff)
Counters
Diffstat (limited to 'src/util')
-rw-r--r--src/util/mod.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/mod.rs b/src/util/mod.rs
index 1eb19113..596282de 100644
--- a/src/util/mod.rs
+++ b/src/util/mod.rs
@@ -8,6 +8,7 @@ pub use buffer::Buffer;
use std::fmt::{self, Debug, Formatter};
use std::hash::Hash;
+use std::num::NonZeroUsize;
use std::path::{Component, Path, PathBuf};
use std::sync::Arc;
@@ -39,6 +40,19 @@ pub fn hash128<T: Hash + ?Sized>(value: &T) -> u128 {
state.finish128().as_u128()
}
+/// Extra methods for [`NonZeroUsize`].
+pub trait NonZeroExt {
+ /// The number `1`.
+ const ONE: Self;
+}
+
+impl NonZeroExt for NonZeroUsize {
+ const ONE: Self = match Self::new(1) {
+ Some(v) => v,
+ None => unreachable!(),
+ };
+}
+
/// Extra methods for [`str`].
pub trait StrExt {
/// The number of code units this string would use if it was encoded in