Reading FTD Files
A FTD file can be parsed from Rust using the ftd
crate:
let doc = ftd::p2::Document::from("some/id", source, lib)?; let msg: String = doc.get("some/id#x)?;
To learn about lib
parameter, checkout the library documentation.
When calling .get()
the type of variable in Rust must have compatible serde::Deserialize implementation. For builtin-types you will see what types they can be deserialized into. record
s can deserialized into corresponding Rust struct
s, and or-type
into Rust enum
.
A Note On ID
When parsing ftd
file, a “library” has to be provided because an ftd
file can refer to another ftd files using the import
feature. So the parsed document contains all data about all the ftd
files referenced, directly or indirectly from the original file.
The original document’s name must be provided when parsing, in our example, it is "some/id"
, and similarly when getting a variable out parsed state, we have to use <doc-id>#<variable-name>
format to generate “full id” of any variable.