[][src]Crate vf_rs

A set of ValueFlows structs and utils auto-generated from the RDF schema.

The schema imports a number of structs from different RDF schemas, and each of them is namespaced in this crate, with the main classes generated living under vf::*.

The structs exported have builder structs defined for them using the wonderful derive_builder crate. So Agent also has a corresponding AgentBuilder struct. Builder structs use the "owned" pattern, meaning the builder methods consume the builder and return a new instance on each call. Given an existing Agent struct instance, you can call myaction.into_builder() to convert (consume) it into an AgentBuilder, which makes immutable updates fairly easy. The builder methods implement Into so any type that has Into implemented for the field type can be passed. Note that builder methods also strip Option, so if a struct field is an Option you can just pass T to the builder method.

This library defines getters and setters for the provided structs via the getset crate. It's important to note that by default, only getters are defined. If you want setters, you can compiled with the feature getset_setters and if you want mutable getters, use getset_getmut. This allows side-stepping some of the enforced functional nature of the library if you find that sort of thing obnoxious.

Features:

  • into_builder - (default) implements .into_builder() for provided structs so existing structs can be modified via the builder pattern.
  • getset_setters - implements setters on the generated structs so they can be mutated in-place via setter methods
  • getset_getmut - implements mutable getters on the generated structs so they can be mutated in-place via &mut getters

Note that all features are enabled when building the docs to give a sense of the library's full abilities.

use vf_rs::vf;

// build a new action with the builder pattern
let agent = vf::Agent::builder()
    .name("Andrew")
    .note("His hands are big")
    .build().unwrap();
assert_eq!(agent.name(), "Andrew");
assert_eq!(agent.note(), &Some("His hands are big".to_string()));
assert_eq!(agent.image(), &None);
// create a new action with a different label
let new_agent = agent.into_builder()
    .note("DOES NOT HAVE SMALL HANDS".to_string())
    .build().unwrap();
assert_eq!(new_agent.name(), "Andrew");
assert_eq!(new_agent.note(), &Some("DOES NOT HAVE SMALL HANDS".to_string()));

Modules

dfc

Supportive module holding the ProductBatch struct used in some of the VF structs

dtype

Supportive module containing NumericUnion (used mainly in the om2 structs)

geo

Supportive module containing SpatialThing used in various VF structs

om2

Supportive module holding some of the structs from om2 (used for measurements and units)

vf

The main ValueFlows module which holds the VF classes.