depends_derives/lib.rs
1use proc_macro::TokenStream;
2use proc_macro_error::proc_macro_error;
3
4/// Implement necessary traits for making this type a valid value in either
5/// an `InputNode` or `DerivedNode`.
6///
7/// ## Hashing
8///
9/// By default, this will assume the type implements `Hash`. If it doesn't,
10/// you must either mark a field you wish to use as a hash with
11/// `#[depends(hash)]`, or mark the type itself as `#[depends(unhashable)]`.
12///
13/// > Note that marking a node as `unhashable` will cause any node with an edge
14/// > to it to consider its dependencies dirty on every resolve. In the vast
15/// > majority of cases you should hash a field instead.
16///
17/// ## Cleaning
18///
19/// By default, this will implement a no-op `Clean` implementation. This
20/// means that nothing will be done to clean the node between resolves.
21///
22/// If you wish to implement `Clean` manually, you can do so by using the
23/// `#[depends(custom_clean)]` attribute on the struct and providing your
24/// implementation.
25///
26/// > Any transient state (such as 'the things which have changed since the
27/// > last resolve') _must_ be cleared up in this method.
28#[proc_macro_error]
29#[proc_macro_derive(Value, attributes(depends))]
30pub fn derive_value(input: TokenStream) -> TokenStream {
31 depends_core::derive_value(input.into()).into()
32}
33
34/// Mark this type as a an `Operation`. This implements `Named` for
35/// debugging, which is a requirement to implement `UpdateDerived`.
36#[proc_macro_error]
37#[proc_macro_derive(Operation)]
38pub fn derive_operation(input: TokenStream) -> TokenStream {
39 depends_core::derive_operation(input.into()).into()
40}
41
42#[cfg(feature = "graphviz")]
43/// Automatically generate graph construction code from a Graphviz graph
44/// definition.
45///
46/// > Note that the ordering of edge definitions is important. For any given
47/// > `Dependencies` type, edges must be defined in the Graphviz specification
48/// > in the order they appear in the `struct`.
49///
50/// Like futures in Rust, the type of a given graph is dependent on the
51/// code itself. Whilst two graphs can be thought of as 'Resolving to a
52/// type T', the actual type of the graph itself depends on exactly which
53/// nodes are constructed to produce that value.
54///
55/// This macro will also safely implement `Send` for the graph definition.
56/// Since `Rc` types within the graph cannot be accessed, it is safe to
57/// send the graph to another thread.
58#[proc_macro_error]
59#[proc_macro_derive(Graph, attributes(depends))]
60pub fn graph(input: TokenStream) -> TokenStream {
61 depends_core::derive_graph(input.into()).into()
62}