scsys_xtask/pipes/watch/builder/impl_inner.rs
1/*
2 Appellation: impl_inner <module>
3 Contrib: @FL03
4*/
5use super::BuilderInner;
6use crate::pipes::watch::{WatcherConfig, WatcherState};
7
8impl BuilderInner {
9 /// Creates a new `BuilderInner` instance with the given configuration and state.
10 ///
11 /// # Arguments
12 ///
13 /// * `config` - A `WatcherConfig` instance containing the configuration for the builder.
14 /// * `state` - A `WatcherState` instance representing the current state of the builder.
15 ///
16 /// # Returns
17 ///
18 /// A new `BuilderInner` instance.
19 pub fn new(config: WatcherConfig, state: WatcherState) -> Self {
20 Self { config, state }
21 }
22 /// returns a new instance of the builder initialized with the given configuration
23 pub fn from_config(config: WatcherConfig) -> Self {
24 Self {
25 config,
26 state: WatcherState::default(),
27 }
28 }
29 /// returns a new instance of the builder initialized with the given state
30 pub fn from_state(state: WatcherState) -> Self {
31 Self {
32 config: WatcherConfig::default(),
33 state,
34 }
35 }
36 /// returns an immutable reference to the current configuration of the pipeline
37 pub const fn config(&self) -> &WatcherConfig {
38 &self.config
39 }
40 /// returns a mutable reference to the current configuration of the pipeline
41 pub fn config_mut(&mut self) -> &mut WatcherConfig {
42 &mut self.config
43 }
44 /// returns an immutable reference to the pipelines current state
45 pub const fn state(&self) -> &WatcherState {
46 &self.state
47 }
48 /// returns a mutable reference to the pipelines current state
49 pub fn state_mut(&mut self) -> &mut WatcherState {
50 &mut self.state
51 }
52 /// set the configuration of the pipeline and return a mutable reference to the instance
53 pub fn set_config(&mut self, config: WatcherConfig) -> &mut Self {
54 self.config = config;
55 self
56 }
57 /// set the state of the pipeline and return a mutable reference to the instance
58 pub fn set_state(&mut self, state: WatcherState) -> &mut Self {
59 self.state = state;
60 self
61 }
62 /// consumes the current instance to create another with the given configuration
63 pub fn with_config(self, config: WatcherConfig) -> Self {
64 Self {
65 config,
66 ..self
67 }
68 }
69 /// consumes the current instance to create another with the given state
70 pub fn with_state(self, state: WatcherState) -> Self {
71 Self { state, ..self }
72 }
73}
74
75impl Default for BuilderInner {
76 fn default() -> Self {
77 Self {
78 config: WatcherConfig::default(),
79 state: WatcherState::default(),
80 }
81 }
82}