redup_bootstrap/dependency/
builder.rs1use std::sync::Arc;
4
5use redup_abstractions::{Dependency, Probe};
6
7use crate::dependency::dependencies::Dependencies;
8use crate::dependency::init::Init;
9use crate::dependency::spec::DependencySpec;
10use crate::error::Error;
11use crate::watch_mode::WatchMode;
12
13pub struct DependencyBuilder<'a> {
16 dependencies: &'a mut Dependencies,
17 spec: DependencySpec,
18}
19
20impl<'a> DependencyBuilder<'a> {
21 pub(crate) fn new(dependencies: &'a mut Dependencies, name: impl Into<String>) -> Self {
23 Self {
24 dependencies,
25 spec: DependencySpec {
26 name: name.into(),
27 probe: None,
28 init: None,
29 mode: None,
30 },
31 }
32 }
33
34 pub fn probe(mut self, probe: impl Probe + 'static) -> Self {
37 self.spec.probe = Some(Arc::new(probe));
38 self
39 }
40
41 pub fn init(mut self, init: Init) -> Self {
43 self.spec.init = Some(init);
44 self
45 }
46
47 pub fn mode(mut self, mode: WatchMode) -> Self {
49 self.spec.mode = Some(mode);
50 self
51 }
52
53 pub fn start(self) -> Result<Dependency, Error> {
56 self.dependencies.register(self.spec)
57 }
58}