use super::Runtime;
use crate::Error;
#[derive(Clone)]
pub(crate) struct Config {
pub(crate) qlen: usize,
pub(crate) nth: usize,
pub(crate) id: u8,
pub(crate) name: &'static str,
}
pub struct Builder {
conf: Config,
}
impl Config {
pub(crate) const fn new(id: u8) -> Self {
Self {
qlen: 0,
nth: 0,
id,
name: "",
}
}
}
impl Builder {
pub const fn new() -> Self {
Self {
conf: Config::new(0),
}
}
pub fn id(&mut self, id: u8) -> &mut Self {
self.conf.id = id;
self
}
pub fn name(&mut self, name: &'static str) -> &mut Self {
self.conf.name = name;
self
}
pub fn qlen(&mut self, len: usize) -> &mut Self {
self.conf.qlen = len;
self
}
pub fn nth(&mut self, nth: usize) -> &mut Self {
self.conf.nth = nth;
self
}
pub fn build(&mut self) -> Result<(), Error> {
Runtime::active(Runtime::new(&self.conf)?)
}
pub unsafe fn rebuild(&mut self) -> Result<(), Error> {
Runtime::reactive(Runtime::new(&self.conf)?)
}
}