rvf - Rust ValueFlows Implementation
Rust implementation of the ValueFlows vocabulary for distributed economic networks.
ValueFlows is a vocabulary for the distributed economic networks of the next economy, designed to coordinate the creation, distribution, and exchange of economic resources. It's based on the REA (Resources, Events, Agents) ontology.
Features
- Complete ValueFlows Implementation: All core types including Agents, Resources, Events, Commitments, Intents, Processes, Transfers, Exchanges, Plans, Proposals, and Recipes
- Production Ready: Comprehensive error handling, extensive test coverage, and proper documentation
- Serialization: Full serde support for JSON and other formats
- Storage Abstraction: Pluggable storage backends with an in-memory implementation included
- Type Safety: Leverages Rust's type system to prevent invalid states
- P2P Ready: All types are serializable and designed for distributed systems
Installation
Add to your Cargo.toml:
[]
= "0.1"
Or with specific features:
[]
= { = "0.1", = ["full"] }
Features Flags
serde(default): Enable serialization/deserialization supportuuid(default): Enable UUID generation for identifiersasync: Enable async support for storage backendsfull: Enable all features
Quick Start
use *;
// Create an agent (person, organization, or ecological agent)
let farmer = builder
.id
.name
.agent_type
.build
.unwrap;
// Create a resource specification (template/type of resource)
let tomato_spec = builder
.id
.name
.build
.unwrap;
// Create an economic resource
let tomatoes = builder
.id
.name
.conforms_to
.primary_accountable
.accounting_quantity
.build
.unwrap;
Core Concepts
Three Layers
ValueFlows operates in three layers:
- Knowledge Layer (Recipes): Templates and patterns for economic activity
- Plan Layer (Intents & Commitments): Offers, requests, and promises
- Observation Layer (Events): Records of what actually happened
Key Types
Agents
Economic actors - people, organizations, or ecological agents.
let person = builder
.id
.name
.agent_type
.build
.unwrap;
Resources
Economic resources that can be created, transferred, or consumed.
let resource = builder
.id
.name
.accounting_quantity
.build
.unwrap;
Actions
Define what a flow does. Available actions:
- Production:
Produce,Consume,Use,Cite - Work:
Work - Transportation:
Pickup,Dropoff - Modification:
Accept,Modify,Combine,Separate - Transfer:
Transfer,TransferAllRights,TransferCustody,Move - Digital:
Copy - Adjustment:
Raise,Lower - Service:
DeliverService
Events
Immutable records of economic activity.
let event = builder
.id
.action
.provider
.receiver
.resource_inventoried_as
.resource_quantity
.build
.unwrap;
Commitments
Promises for future events.
let commitment = builder
.id
.action
.provider
.receiver
.resource_quantity
.build
.unwrap;
Intents
Offers and requests that may lead to commitments.
// An offer (I want to give)
let offer = offer
.id
.provider
.action
.resource_quantity
.build
.unwrap;
// A request (I want to receive)
let request = request
.id
.receiver
.action
.resource_quantity
.build
.unwrap;
// Check if intents match
if offer.matches
Processes
Transformations that take inputs and produce outputs.
let process = builder
.id
.name
.build
.unwrap;
Transfers
Movement of resources between agents.
let transfer = builder
.id
.name
.transfer_type // Rights + Custody
.provider
.receiver
.build
.unwrap;
Exchanges
Reciprocal transfers between parties.
let exchange = builder
.id
.name
.build
.unwrap;
Storage
The library provides a storage abstraction for persistence:
use ;
// Create an in-memory repository
let repo = in_memory;
// Store an agent
repo.put.unwrap;
// Retrieve an agent
let retrieved = repo.get.unwrap;
// Or use get_required which returns an error if not found
let agent = repo.get_required.unwrap;
Production Workflow Example
use *;
// 1. Define the participants
let farm = builder
.id
.name
.agent_type
.build
.unwrap;
let bakery = builder
.id
.name
.agent_type
.build
.unwrap;
// 2. Farm creates a wheat production process
let mut harvest = builder
.id
.name
.build
.unwrap;
harvest.start;
// 3. Record the production event
let production = builder
.id
.action
.provider
.receiver
.output_of
.resource_quantity
.build
.unwrap;
harvest.complete;
// 4. Farm publishes an offer
let offer = offer
.id
.provider
.action
.resource_quantity
.build
.unwrap;
// 5. Bakery makes a matching request
let request = request
.id
.receiver
.action
.resource_quantity
.build
.unwrap;
// 6. Create a commitment when they agree
let mut commitment = builder
.id
.action
.provider
.receiver
.resource_quantity
.build
.unwrap;
// 7. Record the actual transfer
let transfer_event = builder
.id
.action
.provider
.receiver
.resource_quantity
.fulfills
.build
.unwrap;
// 8. Mark commitment as fulfilled
commitment.fulfill;
assert!;
Architecture Notes
P2P Integration
All types implement Clone, Debug, and optionally Serialize/Deserialize, making them suitable for:
- Content-addressable storage (CAS)
- Distributed hash tables (DHT)
- Blockchain/DLT systems
- Event sourcing architectures
Extensibility
The library is designed to be extended:
- Implement custom
Storagebackends for your persistence layer - Add additional metadata through the
noteandin_scope_offields - Use the
Identifiabletrait for automatic ID extraction
Examples
Run the included examples to see ValueFlows in action:
# Farm-to-bakery economic exchange
# AI agent collaboration for research report production
See examples/README.md for detailed documentation, flow diagrams, and comparisons.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.