Skip to main content

triblespace_core/
examples.rs

1//! This module contains an example namespace for use in the documentation.
2//! It is not intended to be used in practice.
3
4use crate::prelude::*;
5/// Example attribute namespace modelling literary works and their authors.
6pub mod literature {
7    #![allow(unused)]
8    use super::*;
9    use crate::prelude::*;
10    use blobschemas::LongString;
11    use valueschemas::Blake3;
12    use valueschemas::GenId;
13    use valueschemas::Handle;
14    use valueschemas::ShortString;
15    use valueschemas::R256;
16
17    attributes! {
18        /// The title of a work.
19        ///
20        /// Small doc paragraph used in the book examples.
21        "A74AA63539354CDA47F387A4C3A8D54C" as pub title: ShortString;
22
23        /// A quote from a work.
24        "6A03BAF6CFB822F04DA164ADAAEB53F6" as pub quote: Handle<Blake3, LongString>;
25
26        /// The author of a work.
27        "8F180883F9FD5F787E9E0AF0DF5866B9" as pub author: GenId;
28
29        /// The first name of an author.
30        "0DBB530B37B966D137C50B943700EDB2" as pub firstname: ShortString;
31
32        /// The last name of an author.
33        "6BAA463FD4EAF45F6A103DB9433E4545" as pub lastname: ShortString;
34
35        /// The number of pages in the work.
36        "FCCE870BECA333D059D5CD68C43B98F0" as pub page_count: R256;
37    }
38}
39
40/// Returns a small sample dataset used in the documentation.
41pub fn dataset() -> TribleSet {
42    let mut set = TribleSet::new();
43    let mut blobs = MemoryBlobStore::new();
44    let author_id = ufoid();
45
46    set += entity! { &author_id @
47       literature::firstname: "Frank",
48       literature::lastname: "Herbert",
49    };
50
51    set += entity! {
52       literature::title: "Dune",
53       literature::author: &author_id,
54       literature::quote: blobs
55           .put("Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.")
56           .unwrap(),
57       literature::quote: blobs
58           .put("I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration. I will face my fear. I will permit it to pass over me and through me. And when it has gone past I will turn the inner eye to see its path. Where the fear has gone there will be nothing. Only I will remain.")
59           .unwrap(),
60    };
61
62    set
63}