ld-core
Serialize and deserialize Rust types as Linked Data. Traits describing how a value maps onto RDF subjects, predicates and graphs, plus derive macros that write those impls for you.
use IriBuf;
use ;
use ;
let value = Foo ;
for quad in to_quads.unwrap
<http://example.org/JohnSmith> <http://example.org/name> "John Smith" .
<http://example.org/JohnSmith> <http://example.org/email> "john.smith@example.org" .
Why this fork
Fork of linked-data by Spruce Systems, Inc.. The traits, the derive attributes and the RDF mapping are unchanged; this fork retargets the crate at a different dependency stack:
- Renamed crates:
linked-data→ld-core,linked-data-derive→ld-core-derive. - Depends on
rdfxinstead ofrdf-types,xsd-rsinstead ofxsd-types,iri-rsinstead ofiref/static-iref, andjstrictinstead ofjson-syntax— which is the point of the fork. - RDF 1.2 aware through
rdfx: triple terms and directional language strings pass through the quad conversions. - Rust 2024 edition, MSRV 1.96 (upstream: 2021, 1.71.1).
- Warning-free build and a reshaped workspace.
Credit and history preserved — see Attribution.
Install
Feature flags
| Flag | Default | Enables |
|---|---|---|
derive |
yes | The Serialize / Deserialize derive macros (ld-core-derive) |
serde |
yes | serde interop, including the json_literal! macro |
Derive attributes
The derive macros read #[ld(...)] attributes:
| Attribute | Meaning |
|---|---|
#[ld(prefix("ex" = "..."))] |
Declares a prefix usable in later attributes |
#[ld(type = "...")] |
Emits an rdf:type triple for the subject |
#[ld(id)] |
The field holds the subject IRI |
#[ld("ex:name")] |
The field is the object of that predicate |
#[ld(flatten)] |
Merges the field's own properties into the parent subject |
#[ld(graph)] |
The field's quads go into a named graph |
#[ld(ignore)] |
The field takes no part in serialization |
See ld-core/examples/ for runnable end-to-end usage:
Interpretations and vocabularies
to_quads produces lexical quads with blank nodes drawn from a generator. When resources are interned — indices from an rdfx vocabulary, say — use the interpreted counterparts instead: to_interpreted_quads, to_interpreted_subject_quads and to_interpreted_graph_quads, which keep values in the interpretation domain rather than materialising IRIs.
MSRV
Rust 1.96 (edition 2024).
Attribution
Original crates: linked-data and linked-data-derive by Spruce Systems, Inc.. Upstream commits are preserved in this repo's history under their original authorship. This fork is a dependency swap onto the rdfx / xsd-rs / iri-rs / jstrict stack, plus edition 2024 polish.
License
Dual-licensed, same as upstream. Pick whichever fits: