kanit

Toy init system
Log | Files | Refs | README | LICENSE

dependencies.rs (1503B)


      1 // A needs B | A -> B
      2 // A uses B | <ignored>
      3 // A wants B | A -> B (if impossible tree, it will be discarded)
      4 // A before B | B -> A
      5 // A after B | A -> B
      6 
      7 use crate::UnitName;
      8 
      9 #[derive(Default, Debug, Clone)]
     10 pub struct Dependencies {
     11     /// The unit requires a previous unit to be started before it.
     12     /// The unit will fail to start if any of its needs fail to start.
     13     pub needs: Vec<UnitName>,
     14     /// The unit uses another unit but doesn't require it.
     15     /// The used unit will not be started, however.
     16     pub uses: Vec<UnitName>,
     17     /// Similar to `uses` with the exception that wanted unit will be started.
     18     pub wants: Vec<UnitName>,
     19     /// The unit should run before another unit.
     20     pub before: Vec<UnitName>,
     21     /// The unit should run after another unit.
     22     pub after: Vec<UnitName>,
     23 }
     24 
     25 impl Dependencies {
     26     pub fn new() -> Self {
     27         Self::default()
     28     }
     29 
     30     pub fn need(&mut self, dependency: UnitName) -> &mut Self {
     31         self.needs.push(dependency);
     32         self
     33     }
     34 
     35     pub fn uses(&mut self, dependency: UnitName) -> &mut Self {
     36         self.uses.push(dependency);
     37         self
     38     }
     39 
     40     pub fn want(&mut self, dependency: UnitName) -> &mut Self {
     41         self.wants.push(dependency);
     42         self
     43     }
     44 
     45     pub fn before(&mut self, dependency: UnitName) -> &mut Self {
     46         self.before.push(dependency);
     47         self
     48     }
     49 
     50     pub fn after(&mut self, dependency: UnitName) -> &mut Self {
     51         self.after.push(dependency);
     52         self
     53     }
     54 }