diff options
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/mod.rs | 14 |
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 |
