Skip to main content

Crate linked_data

Crate linked_data 

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.

§Example

ⓘ
use rdf_syntax::{IriBuf, iri};
use linked_data::{SerializeLinkedData, DeserializeLinkedData};

#[derive(SerializeLinkedData, DeserializeLinkedData)]
#[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: iri!("http://example.org/JohnSmith").to_owned(),
  name: "John Smith".to_owned(),
  email: "john.smith@example.org".to_owned()
};

let quads = linked_data::ser::to_rdf_quads(&value)
  .expect("RDF serialization failed");

for quad in quads {
  println!("{quad} .")
}

This should print the following:

<http://example.org/JohnSmith> <http://example.org/name> "John Smith" .
<http://example.org/JohnSmith> <http://example.org/email> "john.smith@example.org" .

Re-exports§

pub use de::DeserializeLinkedData;
pub use de::LinkedDataDeserializer;
pub use ser::LinkedDataSerializer;
pub use ser::SerializeLinkedData;

Modules§

de
ser

Structs§

RdfUnordered
Utility wrapper to turn lists into unordered collections.