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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use crate::private::Sealed;
use crate::Wikicode;
#[derive(Clone, Debug)]
pub struct ImmutableWikicode {
pub(crate) html: String,
pub(crate) title: Option<String>,
pub(crate) etag: Option<String>,
pub(crate) revid: Option<u64>,
}
impl ImmutableWikicode {
pub fn new(html: &str) -> Self {
Self {
html: html.to_string(),
title: None,
etag: None,
revid: None,
}
}
pub fn html(&self) -> &str {
&self.html
}
pub fn title(&self) -> Option<String> {
self.title.clone()
}
pub fn etag(&self) -> Option<&str> {
self.etag.as_deref()
}
pub fn revision_id(&self) -> Option<u64> {
self.revid
}
pub fn into_mutable(self) -> Wikicode {
self.into()
}
}
impl From<Wikicode> for ImmutableWikicode {
fn from(code: Wikicode) -> Self {
Self {
html: code.to_string(),
revid: code.revision_id(),
title: code.title,
etag: code.etag,
}
}
}
impl From<ImmutableWikicode> for Wikicode {
fn from(immutable: ImmutableWikicode) -> Self {
let mut code = Wikicode::new(&immutable.html);
code.etag = immutable.etag;
code.title = immutable.title;
code
}
}
impl Sealed for ImmutableWikicode {}
#[cfg(test)]
mod tests {
use super::*;
fn assert_sync_send<T: Sync + Send>() {}
#[test]
fn test_immutable() {
assert_sync_send::<ImmutableWikicode>();
}
}