use std::sync::Arc;
use redup_abstractions::{Dependency, Probe};
use crate::dependency::dependencies::Dependencies;
use crate::dependency::init::Init;
use crate::dependency::spec::DependencySpec;
use crate::error::Error;
use crate::watch_mode::WatchMode;
pub struct DependencyBuilder<'a> {
dependencies: &'a mut Dependencies,
spec: DependencySpec,
}
impl<'a> DependencyBuilder<'a> {
pub(crate) fn new(dependencies: &'a mut Dependencies, name: impl Into<String>) -> Self {
Self {
dependencies,
spec: DependencySpec {
name: name.into(),
probe: None,
init: None,
mode: None,
},
}
}
pub fn probe(mut self, probe: impl Probe + 'static) -> Self {
self.spec.probe = Some(Arc::new(probe));
self
}
pub fn init(mut self, init: Init) -> Self {
self.spec.init = Some(init);
self
}
pub fn mode(mut self, mode: WatchMode) -> Self {
self.spec.mode = Some(mode);
self
}
pub fn start(self) -> Result<Dependency, Error> {
self.dependencies.register(self.spec)
}
}