#![deny(unsafe_code)]
mod auth;
mod backend;
mod hostfile;
#[cfg(feature = "jaccl")]
pub mod jaccl;
mod json;
mod keepalive;
mod pool;
mod reduce;
mod ring;
mod socket;
use std::sync::Arc;
use std::time::Duration;
use nuvec_core::Result;
use nuvec_core::distributed::Group;
pub use backend::{Backend, init_backend, is_available};
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct Options {
pub timeout: Duration,
key: auth::Secret,
}
impl Default for Options {
fn default() -> Self {
Self {
timeout: Duration::from_secs(30),
key: auth::Secret::default(),
}
}
}
impl Options {
pub fn timeout(mut self, timeout: Duration) -> Self {
self.timeout = timeout;
self
}
pub fn key(mut self, secret: impl AsRef<[u8]>) -> Self {
self.key = auth::Secret(Some(secret.as_ref().to_vec()));
self
}
}
pub fn init(strict: bool) -> Result<Group> {
init_backend(strict, Backend::Any)
}
pub fn init_with(nodes: &[Vec<String>], rank: usize, options: &Options) -> Result<Group> {
if nodes.len() <= 1 {
return Ok(Group::single());
}
let key = options.key.key()?;
let ring = ring::Ring::connect(nodes, rank, options.timeout, key.as_ref())?;
Ok(Group::new(Arc::new(ring)))
}