Use NonZero* where applicable

This commit is contained in:
Adrian Heine 2023-03-08 11:46:47 +01:00
parent ac1c06dd31
commit 5045c3494d
4 changed files with 12 additions and 7 deletions

View file

@ -1,14 +1,16 @@
use crate::command_runner::CommandRunner;
use crate::symbols::Symbol;
use async_trait::async_trait;
use nonzero_ext::nonzero;
use std::error::Error;
use std::num::NonZeroU32;
use std::path::Path;
#[derive(Debug)]
pub struct Key<C, P> {
file_path: P,
command_runner: C,
bits: u32,
bits: NonZeroU32,
}
impl<C, P> Key<C, P> {
@ -16,7 +18,7 @@ impl<C, P> Key<C, P> {
Self {
file_path,
command_runner,
bits: 4096,
bits: nonzero!(4096u32), // FIXME: Policy
}
}
}

View file

@ -1,4 +1,5 @@
use std::fmt::Display;
use std::num::NonZeroUsize;
use std::path::Path;
#[must_use]
@ -101,11 +102,11 @@ impl<T: AsRef<Path>> SocketSpec for T {
}
#[derive(Debug)]
pub struct LocalTcpSocket(usize);
pub struct LocalTcpSocket(NonZeroUsize);
impl LocalTcpSocket {
#[must_use]
pub const fn new(x: usize) -> Self {
pub const fn new(x: NonZeroUsize) -> Self {
Self(x)
}
}

View file

@ -1,9 +1,10 @@
use std::fmt::{Display, Error, Formatter};
use std::num::NonZeroUsize;
use std::path::Path;
#[derive(Clone, Debug, PartialEq, Hash, Eq)]
pub struct FpmPoolConfig {
max_children: usize,
max_children: NonZeroUsize,
custom: Option<String>,
}
@ -19,14 +20,14 @@ impl Display for FpmPoolConfig {
impl From<usize> for FpmPoolConfig {
fn from(max_children: usize) -> Self {
Self {
max_children,
max_children: NonZeroUsize::try_from(max_children).unwrap(),
custom: None,
}
}
}
impl FpmPoolConfig {
pub fn new(max_children: usize, custom: impl Into<String>) -> Self {
pub fn new(max_children: NonZeroUsize, custom: impl Into<String>) -> Self {
Self {
max_children,
custom: Some(custom.into()),