#economics #define #rea #valueflows


A set of classes generated from the ValueFlows RDF schema

25 releases

0.4.0 Mar 31, 2024
0.3.16 Sep 21, 2020
0.3.15 Aug 14, 2020
0.3.14 Jun 8, 2020
0.1.2 Apr 7, 2020

#418 in Data structures

Download history 10/week @ 2024-03-15 191/week @ 2024-03-29 8/week @ 2024-04-05

867 downloads per month

Custom license

1.5K SLoC


This crate is a set of (de)serializable structs based on the ValueFlows schema, along with various utilities for working with ValueFlows.

The goal of this library is to provide a serializable type layer for ValueFlows such that it could be used in other libs/apps to create a VF system. This lib does not deal with any kind of storage mechanism.


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 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 for example 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 myagent.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<T> 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.


  • 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 agent with the builder pattern, using String for the id field type
let agent: vf::Agent = vf::Agent::builder()
    .note(Some("His hands are big".into()))
assert_eq!(agent.name(), "Andrew");
assert_eq!(agent.note(), &Some("His hands are big".into()));
assert_eq!(agent.image(), &None);
// create a new agent with a different label
let new_agent = agent.into_builder()
    .note(Some("DOES NOT HAVE SMALL HANDS".into()))
assert_eq!(new_agent.name(), "Andrew");
assert_eq!(new_agent.note(), &Some("DOES NOT HAVE SMALL HANDS".into()));

Note that this library contains absolutely no ValueFlows logic and exists solely as a definition for VF types.


~128K SLoC