nntp_proxy/types/config/
cache.rs1use std::num::NonZeroUsize;
4
5nonzero_newtype! {
6 pub struct CacheCapacity(NonZeroUsize: usize, serialize as serialize_u64);
10}
11
12impl CacheCapacity {
13 pub const DEFAULT: Self = Self(NonZeroUsize::new(1000).unwrap());
15}
16
17impl std::str::FromStr for CacheCapacity {
18 type Err = std::num::ParseIntError;
19
20 fn from_str(s: &str) -> Result<Self, Self::Err> {
21 let value = s.parse::<usize>()?;
22 Ok(Self::new(value).unwrap_or(Self::DEFAULT))
23 }
24}
25
26impl PartialOrd for CacheCapacity {
27 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
28 Some(self.cmp(other))
29 }
30}
31
32impl Ord for CacheCapacity {
33 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
34 self.get().cmp(&other.get())
35 }
36}