Skip to main content

Crate ld_core

Crate ld_core 

Source
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) — the Serialize and Deserialize derive macros.
  • serde (default) — serde interop, including the json_literal! macro that maps a serde type onto an rdf:JSON literal.

Macros§

json_literal
Implements the Linked-Data resource traits for a serde type, mapping it onto a canonical rdf:JSON literal.

Structs§

Anonymous
Anonymous lexical representation.
AnonymousBinding
Binding of a value to a predicate, serialized on an anonymous subject.
AnonymousGraph
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§

BorrowedRdfTerm
Borrowed RDF term.
Context
Position a value occupies while being visited, used to report errors.
ContextIris
Error context with its resources resolved into IRIs.
CowRdfLiteral
RDF literal that is either borrowed or owned.
CowRdfTerm
RDF term that is either borrowed or owned.
CowRef
Value that is either borrowed or owned, without requiring ToOwned.
FromLinkedDataError
Error raised while deserializing a value from Linked Data.
IntoQuadsError
Error raised while serializing a value into quads.
OwnedRdfTerm
Owned RDF term.
RdfLiteral
Owned RDF literal, kept in its most specific known form.
RdfLiteralRef
Borrowed RDF literal, kept in its most specific known form.
ResourceInterpretation
Resource interpretation.
ResourceOrIriRef
Reference to a resource, either interpreted or lexical.

Constants§

RDF_JSON
The rdf:JSON datatype IRI, http://www.w3.org/1999/02/22-rdf-syntax-ns#JSON.

Traits§

AsRdfLiteral
Type that can be borrowed as an RDF literal of a given datatype.
GraphVisitor
Visitor over the subjects of an RDF graph.
LinkedData
Linked-Data type.
LinkedDataDeserialize
Type that can be deserialized from an RDF dataset.
LinkedDataDeserializePredicateObjects
Type that can be deserialized from the objects of a predicate.
LinkedDataDeserializeSubject
Type that can be deserialized from a subject of an RDF dataset.
LinkedDataGraph
Serialize a Linked-Data graph.
LinkedDataPredicateObjects
Type representing the objects of an RDF subject’s predicate binding.
LinkedDataResource
Type that can have an interpretation.
LinkedDataResourceRef
Type that can have an interpretation bound to the given lifetime.
LinkedDataSubject
Serialize a Linked-Data node.
PredicateObjectsVisitor
Visitor over the objects of a predicate.
RdfLiteralValue
Value that can be stored as an RDF literal.
SubjectVisitor
Visitor over the properties of an RDF subject.
Visitor
RDF dataset visitor.

Functions§

to_interpreted_graph_quads
Serializes value as the content of graph, in the interpretation domain.
to_interpreted_quads
Serializes value into quads whose components are resources of interpretation.
to_interpreted_subject_quads
Serializes value as a single subject in graph, returning its resource and the quads describing it.
to_lexical_quads
Serializes value into lexical quads, drawing blank node identifiers from generator.
to_lexical_quads_with
Serializes value into lexical quads, using the given interpretation to resolve resources into IRIs, blank ids and literals.
to_lexical_subject_quads
Serializes value as a single subject in graph, drawing blank node identifiers from generator.
to_lexical_subject_quads_with
Serializes value as a single subject in graph, returning its identifier and the lexical quads describing it.
to_quads
Serializes value into quads, drawing blank node identifiers from generator.
to_quads_with
Serializes value into quads, using the given interpretation.

Type Aliases§

InterpretedQuad
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.
RdfTermRef
Borrowed lexical RDF term.

Derive Macros§

Deserialize
Derives the FromLinkedData deserialization traits from #[ld(...)] attributes.
Serialize
Derives the LinkedData serialization traits from #[ld(...)] attributes.