1
- //! The smallest units of data, consiting of a Subject, a Property and a Value
1
+ //! The smallest units of data, consisting of a Subject, a Property and a Value
2
2
3
- use crate :: { errors:: AtomicResult , values:: Value } ;
3
+ use crate :: {
4
+ errors:: AtomicResult ,
5
+ values:: { ReferenceString , SortableValue , Value } ,
6
+ } ;
4
7
5
- /// The Atom is the (non-validated) string representation of a piece of data.
6
- /// It's RichAtom sibling provides some extra methods.
8
+ /// The Atom is the smallest meaningful piece of data.
9
+ /// It describes how one value relates to a subject.
10
+ /// A [Resource] can be converted into a bunch of Atoms.
7
11
#[ derive( Clone , Debug ) ]
8
12
pub struct Atom {
9
13
/// The URL where the resource is located
@@ -27,6 +31,35 @@ impl Atom {
27
31
let base_path = format ! ( "{} {}" , self . subject, self . property) ;
28
32
self . value . to_subjects ( Some ( base_path) )
29
33
}
34
+
35
+ /// Converts one Atom to a series of stringified values that can be indexed.
36
+ pub fn to_indexable_atoms ( & self ) -> Vec < IndexAtom > {
37
+ let sort_value = self . value . to_sortable_string ( ) ;
38
+ let index_atoms = match & self . value . to_reference_index_strings ( ) {
39
+ Some ( v) => v,
40
+ None => return vec ! [ ] ,
41
+ }
42
+ . iter ( )
43
+ . map ( |v| IndexAtom {
44
+ ref_value : v. into ( ) ,
45
+ sort_value : sort_value. clone ( ) ,
46
+ subject : self . subject . clone ( ) ,
47
+ property : self . property . clone ( ) ,
48
+ } )
49
+ . collect ( ) ;
50
+ index_atoms
51
+ }
52
+ }
53
+
54
+ /// Differs from a regular [Atom], since the value here is always a string,
55
+ /// and in the case of ResourceArrays, only a _single_ subject is used for each atom.
56
+ /// One IndexAtom for every member of the ResourceArray is created.
57
+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
58
+ pub struct IndexAtom {
59
+ pub subject : String ,
60
+ pub property : String ,
61
+ pub ref_value : ReferenceString ,
62
+ pub sort_value : SortableValue ,
30
63
}
31
64
32
65
impl std:: fmt:: Display for Atom {
0 commit comments