1use crate::private::Sealed;
19use crate::Wikicode;
20
21#[derive(Clone, Debug)]
28pub struct ImmutableWikicode {
29 pub(crate) html: String,
30 pub(crate) title: Option<String>,
31 pub(crate) etag: Option<String>,
32 pub(crate) revid: Option<u64>,
33}
34
35impl ImmutableWikicode {
36 pub fn new(html: &str) -> Self {
37 Self {
38 html: html.to_string(),
39 title: None,
40 etag: None,
41 revid: None,
42 }
43 }
44
45 pub fn html(&self) -> &str {
46 &self.html
47 }
48
49 pub fn title(&self) -> Option<String> {
50 self.title.clone()
51 }
52
53 pub fn etag(&self) -> Option<&str> {
54 self.etag.as_deref()
55 }
56
57 pub fn revision_id(&self) -> Option<u64> {
58 self.revid
59 }
60
61 pub fn into_mutable(self) -> Wikicode {
62 self.into()
63 }
64}
65
66impl From<Wikicode> for ImmutableWikicode {
67 fn from(code: Wikicode) -> Self {
68 Self {
69 html: code.to_string(),
70 revid: code.revision_id(),
71 title: code.title,
72 etag: code.etag,
73 }
74 }
75}
76
77impl From<ImmutableWikicode> for Wikicode {
78 fn from(immutable: ImmutableWikicode) -> Self {
79 let mut code = Wikicode::new(&immutable.html);
80 code.etag = immutable.etag;
81 code.title = immutable.title;
82 code
83 }
84}
85
86impl Sealed for ImmutableWikicode {}
87
88#[cfg(test)]
89mod tests {
90 use super::*;
91
92 fn assert_sync_send<T: Sync + Send>() {}
93
94 #[test]
95 fn test_immutable() {
96 assert_sync_send::<ImmutableWikicode>();
97 }
98}