Browse Source

Use NonZero* where applicable

master
Adrian Heine 1 year ago
parent
commit
5045c3494d
  1. 1
      Cargo.toml
  2. 6
      src/symbols/tls/key.rs
  3. 5
      src/templates/nginx/server.rs
  4. 7
      src/templates/php.rs

1
Cargo.toml

@ -15,6 +15,7 @@ once_cell = "1.4"
slog = { version = "2", features = ["max_level_trace", "release_max_level_trace"] } slog = { version = "2", features = ["max_level_trace", "release_max_level_trace"] }
slog-term = "2.5" slog-term = "2.5"
slog-async = "2.7" slog-async = "2.7"
nonzero_ext = "0.3.0"
[dev-dependencies] [dev-dependencies]
tempfile = "3" tempfile = "3"

6
src/symbols/tls/key.rs

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

5
src/templates/nginx/server.rs

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

7
src/templates/php.rs

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

Loading…
Cancel
Save