Expand description
This library provides primitive traits to serialize and deserialize
Linked-Data types. It is shipped with derive macros (using the derive
feature) that can automatically implement those primitives for you.
A value is described as a set of RDF quads: LinkedDataSubject says
which properties a subject carries, LinkedDataPredicateObjects which
objects a predicate points at, and LinkedDataGraph which graph they
belong to. The derive macros implement all of them from #[ld(...)]
attributes.
§Example
use iri_rs::IriBuf;
use ld_core::rdfx::{RdfDisplay, generator};
use ld_core::{Deserialize, Serialize, to_quads};
#[derive(Serialize, Deserialize)]
#[ld(prefix("ex" = "http://example.org/"))]
struct Foo {
#[ld(id)]
id: IriBuf,
#[ld("ex:name")]
name: String,
#[ld("ex:email")]
email: String,
}
let value = Foo {
id: IriBuf::new("http://example.org/JohnSmith".to_owned()).unwrap(),
name: "John Smith".to_owned(),
email: "john.smith@example.org".to_owned(),
};
let quads = to_quads(generator::Blank::new(), &value).unwrap();
let output: Vec<String> = quads.iter().map(|q| format!("{} .", q.rdf_display())).collect();
assert!(output.contains(
&r#"<http://example.org/JohnSmith> <http://example.org/name> "John Smith" ."#.to_owned()
));§Feature flags
derive(default) — theSerializeandDeserializederive macros.serde(default) —serdeinterop, including thejson_literal!macro that maps aserdetype onto anrdf:JSONliteral.
Macros§
- json_
literal - Implements the Linked-Data resource traits for a
serdetype, mapping it onto a canonicalrdf:JSONliteral.
Structs§
- Anonymous
- Anonymous lexical representation.
- Anonymous
Binding - Binding of a value to a predicate, serialized on an anonymous subject.
- Anonymous
Graph - Wrapper serializing its value as an anonymous graph.
- Ref
- Wrapper serializing its value as a reference: the subject is emitted as an object, without its own properties.
Enums§
- Borrowed
RdfTerm - Borrowed RDF term.
- Context
- Position a value occupies while being visited, used to report errors.
- Context
Iris - Error context with its resources resolved into IRIs.
- CowRdf
Literal - RDF literal that is either borrowed or owned.
- CowRdf
Term - RDF term that is either borrowed or owned.
- CowRef
- Value that is either borrowed or owned, without requiring
ToOwned. - From
Linked Data Error - Error raised while deserializing a value from Linked Data.
- Into
Quads Error - Error raised while serializing a value into quads.
- Owned
RdfTerm - Owned RDF term.
- RdfLiteral
- Owned RDF literal, kept in its most specific known form.
- RdfLiteral
Ref - Borrowed RDF literal, kept in its most specific known form.
- Resource
Interpretation - Resource interpretation.
- Resource
OrIri Ref - Reference to a resource, either interpreted or lexical.
Constants§
- RDF_
JSON - The
rdf:JSONdatatype IRI, http://www.w3.org/1999/02/22-rdf-syntax-ns#JSON.
Traits§
- AsRdf
Literal - Type that can be borrowed as an RDF literal of a given datatype.
- Graph
Visitor - Visitor over the subjects of an RDF graph.
- Linked
Data - Linked-Data type.
- Linked
Data Deserialize - Type that can be deserialized from an RDF dataset.
- Linked
Data Deserialize Predicate Objects - Type that can be deserialized from the objects of a predicate.
- Linked
Data Deserialize Subject - Type that can be deserialized from a subject of an RDF dataset.
- Linked
Data Graph - Serialize a Linked-Data graph.
- Linked
Data Predicate Objects - Type representing the objects of an RDF subject’s predicate binding.
- Linked
Data Resource - Type that can have an interpretation.
- Linked
Data Resource Ref - Type that can have an interpretation bound to the given lifetime.
- Linked
Data Subject - Serialize a Linked-Data node.
- Predicate
Objects Visitor - Visitor over the objects of a predicate.
- RdfLiteral
Value - Value that can be stored as an RDF literal.
- Subject
Visitor - Visitor over the properties of an RDF subject.
- Visitor
- RDF dataset visitor.
Functions§
- to_
interpreted_ graph_ quads - Serializes
valueas the content ofgraph, in the interpretation domain. - to_
interpreted_ quads - Serializes
valueinto quads whose components are resources ofinterpretation. - to_
interpreted_ subject_ quads - Serializes
valueas a single subject ingraph, returning its resource and the quads describing it. - to_
lexical_ quads - Serializes
valueinto lexical quads, drawing blank node identifiers fromgenerator. - to_
lexical_ quads_ with - Serializes
valueinto lexical quads, using the given interpretation to resolve resources into IRIs, blank ids and literals. - to_
lexical_ subject_ quads - Serializes
valueas a single subject ingraph, drawing blank node identifiers fromgenerator. - to_
lexical_ subject_ quads_ with - Serializes
valueas a single subject ingraph, returning its identifier and the lexical quads describing it. - to_
quads - Serializes
valueinto quads, drawing blank node identifiers fromgenerator. - to_
quads_ with - Serializes
valueinto quads, using the given interpretation.
Type Aliases§
- Interpreted
Quad - RDF quad whose components are resources of the interpretation
I. - RdfId
- Node identifier: an IRI or a blank node identifier.
- RdfQuad
- Lexical RDF quad.
- RdfTerm
- Lexical RDF term.
- RdfTerm
Ref - Borrowed lexical RDF term.
Derive Macros§
- Deserialize
- Derives the
FromLinkedDatadeserialization traits from#[ld(...)]attributes. - Serialize
- Derives the
LinkedDataserialization traits from#[ld(...)]attributes.