fud_core/exec/data.rs
1use crate::run;
2use cranelift_entity::entity_impl;
3
4/// A State is a type of file that Operations produce or consume.
5pub struct State {
6 /// The name of the state, for the UI.
7 pub name: String,
8
9 /// The file extensions that this state can be represented by.
10 ///
11 /// The first extension in the list is used when generating a new filename for the state. If
12 /// the list is empty, this is a "pseudo-state" that doesn't correspond to an actual file.
13 /// Pseudo-states can only be final outputs; they are appropraite for representing actions that
14 /// interact directly with the user, for example.
15 pub extensions: Vec<String>,
16}
17
18impl State {
19 /// Check whether a filename extension indicates this state.
20 pub fn ext_matches(&self, ext: &str) -> bool {
21 self.extensions.iter().any(|e| e == ext)
22 }
23
24 /// Is this a "pseudo-state": doesn't correspond to an actual file, and must be an output state?
25 pub fn is_pseudo(&self) -> bool {
26 self.extensions.is_empty()
27 }
28}
29
30/// A reference to a State.
31#[derive(Copy, Clone, PartialEq, Eq, Hash)]
32pub struct StateRef(u32);
33entity_impl!(StateRef, "state");
34
35/// An Operation transforms files from one State to another.
36pub struct Operation {
37 pub name: String,
38 pub input: StateRef,
39 pub output: StateRef,
40 pub setups: Vec<SetupRef>,
41 pub emit: Box<dyn run::EmitBuild>,
42}
43
44/// A reference to an Operation.
45#[derive(Copy, Clone, PartialEq, Eq, Hash)]
46pub struct OpRef(u32);
47entity_impl!(OpRef, "op");
48
49/// A Setup runs at configuration time and produces Ninja machinery for Operations.
50pub struct Setup {
51 pub name: String,
52 pub emit: Box<dyn run::EmitSetup>,
53}
54
55/// A reference to a Setup.
56#[derive(Copy, Clone, PartialEq, Eq, Hash)]
57pub struct SetupRef(u32);
58entity_impl!(SetupRef, "setup");