1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use super::*;
use std::collections::btree_map::Values;
#[derive(Debug, Clone)]
pub struct DocumentAuthor {
pub name: String,
pub email: Option<String>,
pub org: Option<String>,
}
impl DocumentAuthor {
#[inline]
pub fn new(name: impl Into<String>) -> DocumentAuthor {
Self { name: name.into(), email: None, org: None }
}
}
impl NoteDocument {
#[inline]
pub fn authors(&self) -> DocumentAuthorIter {
DocumentAuthorIter { inner: self.meta.authors.values() }
}
#[inline]
pub fn set_authors(&mut self, authors: BTreeMap<String, DocumentAuthor>) {
self.meta.authors = authors
}
#[inline]
pub fn get_author(&self, name: &str) -> Option<&DocumentAuthor> {
self.meta.authors.get(name)
}
#[inline]
pub fn get_author_mut(&mut self, name: &str) -> Option<&mut DocumentAuthor> {
self.meta.authors.get_mut(name)
}
#[inline]
pub fn add_author(&mut self, author: DocumentAuthor) -> Option<DocumentAuthor> {
self.meta.authors.insert(author.name.to_owned(), author)
}
}
#[derive(Debug)]
pub struct DocumentAuthorIter<'a> {
inner: Values<'a, String, DocumentAuthor>,
}
impl<'a> Iterator for DocumentAuthorIter<'a> {
type Item = &'a DocumentAuthor;
fn next(&mut self) -> Option<Self::Item> {
self.inner.next()
}
}