#[cfg(feature = "multithreaded")]
use std::num::NonZeroUsize;
use crate::global::flags::Flags;
#[cfg(feature = "crypto")]
use crate::crypto;
#[derive(Debug, Clone)]
pub struct BuilderConfig {
#[cfg(feature = "multithreaded")]
pub num_threads: NonZeroUsize,
pub flags: Flags,
#[cfg(feature = "crypto")]
#[cfg_attr(docsrs, doc(cfg(feature = "crypto")))]
pub signing_key: Option<crypto::SigningKey>,
}
impl BuilderConfig {
#[cfg(feature = "multithreaded")]
pub fn threads(mut self, num_threads: usize) -> Self {
if let Some(n) = NonZeroUsize::new(num_threads) {
self.num_threads = n;
}
self
}
#[cfg(feature = "crypto")]
pub fn keypair(mut self, keypair: crypto::SigningKey) -> Self {
self.signing_key = Some(keypair);
self
}
pub fn flags(mut self, flags: Flags) -> Self {
self.flags = flags;
self
}
#[cfg(feature = "crypto")]
pub fn load_keypair<T: std::io::Read>(&mut self, handle: T) -> crate::global::error::InternalResult {
crate::crypto_utils::read_keypair(handle).map(|kp| self.signing_key = Some(kp))
}
}
impl<'a> Default for BuilderConfig {
fn default() -> BuilderConfig {
BuilderConfig {
#[cfg(feature = "multithreaded")]
num_threads: unsafe { NonZeroUsize::new_unchecked(4) },
flags: Flags::default(),
#[cfg(feature = "crypto")]
signing_key: None,
}
}
}