Skip to main content

linked_data/
lib.rs

1//! This library provides primitive traits to serialize and deserialize
2//! Linked-Data types. It is shipped with derive macros (using the `derive`
3//! feature) that can automatically implement those primitives for you.
4//!
5//! # Example
6//!
7//! ```ignore
8//! use rdf_syntax::{IriBuf, iri};
9//! use linked_data::{SerializeLinkedData, DeserializeLinkedData};
10//!
11//! #[derive(SerializeLinkedData, DeserializeLinkedData)]
12//! #[ld(prefix("ex" = "http://example.org/"))]
13//! struct Foo {
14//!   #[ld(id)]
15//!   id: IriBuf,
16//!
17//!   #[ld("ex:name")]
18//!   name: String,
19//!
20//!   #[ld("ex:email")]
21//!   email: String
22//! }
23//!
24//! let value = Foo {
25//!   id: iri!("http://example.org/JohnSmith").to_owned(),
26//!   name: "John Smith".to_owned(),
27//!   email: "john.smith@example.org".to_owned()
28//! };
29//!
30//! let quads = linked_data::ser::to_rdf_quads(&value)
31//!   .expect("RDF serialization failed");
32//!
33//! for quad in quads {
34//!   println!("{quad} .")
35//! }
36//! ```
37//!
38//! This should print the following:
39//! ```text
40//! <http://example.org/JohnSmith> <http://example.org/name> "John Smith" .
41//! <http://example.org/JohnSmith> <http://example.org/email> "john.smith@example.org" .
42//! ```
43#[doc(hidden)]
44pub use rdf_syntax;
45
46#[cfg(feature = "derive")]
47pub use linked_data_derive::{DeserializeLinkedData, SerializeLinkedData};
48
49pub mod de;
50mod r#impl;
51pub mod ser;
52
53pub use de::{DeserializeLinkedData, LinkedDataDeserializer};
54pub use ser::{LinkedDataSerializer, SerializeLinkedData};
55
56/// Utility wrapper to turn lists into unordered collections.
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
58pub struct RdfUnordered<T>(pub T);