lib/models/entry.rs
1//! Defines the [`Entry`] struct.
2
3use std::collections::HashMap;
4
5use serde::Serialize;
6
7use super::annotation::Annotation;
8use super::book::Book;
9
10/// A type alias represening how [`Entry`]s are organized.
11///
12/// [`Entries`] is a `HashMap` composed of `key:value` pairs of where the value is an [`Entry`] and
13/// the key is the unique id of its [`Book`], taken from the [`BookMetadata::id`][book-metadata-id]
14/// field.
15///
16/// For example:
17///
18/// ```plaintext
19/// Entries
20/// │
21/// ├── ID: Entry
22/// ├── ID: Entry
23/// └── ...
24/// ```
25///
26/// [book-metadata-id]: crate::models::book::BookMetadata::id
27pub type Entries = HashMap<String, Entry>;
28
29/// A container struct that stores a [`Book`] and its respective [`Annotation`]s.
30#[derive(Debug, Default, Clone, Serialize)]
31pub struct Entry {
32 /// The entry's [`Book`].
33 pub book: Book,
34
35 /// The entry's [`Annotation`]s.
36 pub annotations: Vec<Annotation>,
37}
38
39impl From<Book> for Entry {
40 /// Constructs an instance of [`Entry`] via a [`Book`] object. This is the primary way
41 /// [`Entry`]s are created.
42 fn from(book: Book) -> Self {
43 Self {
44 book,
45 annotations: Vec::new(),
46 }
47 }
48}