LinksPlatform's Platform.Data Class Library for Rust.
This crate provides core data types and traits for the Links Platform — an associative data storage system. It defines the fundamental abstractions for working with links (doublets) in Rust.
The platform-data crate provides:
LinkType— A trait defining the numeric types that can be used as link identifiersLinks— The core trait for CRUD operations on doublet links storageFlow— Control flow type for iteration operations (Continue/Break)Query— A wrapper for link queries using copy-on-write semanticsPoint— A structure representing a repeating elementHybrid— A type for handling internal and external link referencesLinksConstants— Configuration constants for links storageAddrToRaw/RawToAddr— Converters between address and raw representations
Add this to your Cargo.toml:
[dependencies]
platform-data = "0.1.0-beta.3"use platform_data::{query, Query, ToQuery};
// Create queries using the macro
let q: Query<usize> = query![1, 2, 3];
assert_eq!(q.len(), 3);
// Empty query
let empty: Query<usize> = query![];
assert!(empty.is_empty());use platform_data::Flow;
let mut collected = vec![];
// Use Flow with try_for_each by converting to ControlFlow
(0..20).try_for_each(|i| {
collected.push(i);
if i == 10 { Flow::Break.into_control_flow() } else { Flow::Continue.into_control_flow() }
});
assert_eq!(collected, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// Or use Flow directly with manual iteration
let mut collected2 = vec![];
for i in 0..20 {
collected2.push(i);
let flow = if i == 10 { Flow::Break } else { Flow::Continue };
if flow.is_break() {
break;
}
}
assert_eq!(collected2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);use platform_data::Point;
let point = Point::new(42, 5);
assert_eq!(point.len(), 5);
assert_eq!(point.get(0), Some(&42));
assert_eq!(point.get(4), Some(&42));
// Iterate over repeated elements
for value in point {
assert_eq!(value, 42);
}use platform_data::{AddrToRaw, RawToAddr, Hybrid};
let addr: usize = 100;
// Convert address to raw and back
let raw = AddrToRaw.convert(addr);
let restored = RawToAddr.convert(raw);
assert_eq!(restored, addr);
// Hybrid values
let internal = Hybrid::internal(42usize);
assert!(internal.is_internal());
let external = Hybrid::external(42usize);
assert!(external.is_external());use platform_data::{Links, LinkType, LinksConstants, Flow, Error, ReadHandler, WriteHandler};
// The Links trait provides CRUD operations for doublet links:
// - constants_links() - get storage configuration
// - count_links(query) - count matching links
// - create_links(query, handler) - create new links
// - each_links(query, handler) - iterate over matching links
// - update_links(query, replacement, handler) - update existing links
// - delete_links(query, handler) - delete links| Type | Description |
|---|---|
LinkType |
Trait bound for numeric types usable as link identifiers (unsigned integers) |
Links<T> |
Main trait defining CRUD operations for links storage |
Flow |
Control flow enum: Continue or Break for iteration control |
Query<'a, T> |
Copy-on-write query wrapper for efficient link queries |
Point<T> |
Structure representing a single value repeated multiple times |
Hybrid<T> |
Type for distinguishing internal and external link references |
LinksConstants<T> |
Configuration constants including null, any, continue, break, etc. |
Error<'a, T> |
Error type for links operations |
| Alias | Description |
|---|---|
ReadHandler<'a, T> |
Handler for read operations: &mut dyn FnMut(&[T]) -> Flow |
WriteHandler<'a, T> |
Handler for write operations: &mut dyn FnMut(&[T], &[T]) -> Flow |
| Type | Description |
|---|---|
AddrToRaw |
Converts link address to raw representation |
RawToAddr |
Converts raw representation back to link address |
This crate requires Rust 1.79 or later (stable toolchain). The associated_type_bounds feature used for Error: bounds was stabilized in Rust 1.79.
- beef — Faster and more compact Cow implementation
- funty — Fundamental type unification
- thiserror — Derive macro for error types
- mem-rs — Memory management for Links Platform
- trees-rs — Tree structures for Links Platform
- Data.Doublets — C# implementation of doublet links
Ask questions at stackoverflow.com/tags/links-platform (or with tag links-platform) to get our free support.
You can also get real-time support on our official Discord server.
This project is licensed under the Unlicense — released into the public domain.