[][src]Crate vf_rs

A set of ValueFlows structs and utils auto-generated from the RDF schema. The structs are all serde-(de)serializable and are generically typed to allow a number of different methods of data modeling.

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::*.

Given the nature of this library, it's important that various use cases are possible. For instance, you might want to model a VF system with all types tightly linked to each other as structs. You might want to loosely link the objects together with IDs (such as when storing in a normalized database). This means that the VF structs exported have generics for their identity field (id) as well as for any references to other VF objects. This allows using whatever types are desired when building out your desired system.

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. The best way to create builders is by using the built-in builder() function for each type (ie, Agent::builder()). Also, 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, using String for the id field type
let agent: vf::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

geo

Supportive module containing SpatialThing used in various VF structs

vf

The main ValueFlows module which holds the VF classes.