Macro from_dot_file

Source
from_dot_file!() { /* proc-macro */ }
Expand description

Imports a DOT graph contained in a file.

Notice that the import happens at compile time. This means the provided file must exist at compile time. This also means that modifying the graph file without recompiling has no effect. This macro generates a graph declaration that corresponds to the graph in the file. All the parsing happens at compile time. If you want to import dynamically a graph (i.e. at compile time), use dot_parser::ast::Graph::from_file instead.

This macro expects a single literal argument which is the path of the file to read.

This macro will fail if:

  • the number of arguments is not exactly 1; or
  • the file can not be read; or
  • the content of the file is not a valid DOT graph.

For example, provided that the file /tmp/graph.dot contains:

digraph {
A -> B
}

Using:

let graph = from_dot!("/tmp/graph.dot");

is roughtly equivalent to:

let graph = Graph::<(&'static str, &'static str)> {
    strict: false,
    is_digraph: true,
    name: Option::None,
    stmts: StmtList {
        stmts: vec![
            Stmt::EdgeStmt(EdgeStmt {
                from: Either::Left(NodeID {
                    id: "A".to_string(),
                    port: Option::None,
                }),
                next: EdgeRHS {
                    to: Either::Left(NodeID {
                        id: "B".to_string(),
                        port: Option::None,
                    }),
                    next: Option::None,
                },
                attr: Option::None,
            }),
        ]
    },
};