vimwiki_core/lang/elements/blocks/inline/
math.rs1use crate::StrictEq;
2use derive_more::{AsRef, Constructor, Display};
3use serde::{Deserialize, Serialize};
4use std::borrow::Cow;
5
6#[derive(
7 AsRef,
8 Constructor,
9 Clone,
10 Debug,
11 Display,
12 Eq,
13 PartialEq,
14 Hash,
15 Serialize,
16 Deserialize,
17)]
18#[as_ref(forward)]
19pub struct MathInline<'a>(
20 Cow<'a, str>,
22);
23
24impl<'a> MathInline<'a> {
25 pub fn as_str(&self) -> &str {
38 self.0.as_ref()
39 }
40}
41
42impl MathInline<'_> {
43 pub fn as_borrowed(&self) -> MathInline {
44 use self::Cow::*;
45
46 let formula = Cow::Borrowed(match &self.0 {
47 Borrowed(x) => *x,
48 Owned(x) => x.as_str(),
49 });
50
51 MathInline::new(formula)
52 }
53
54 pub fn into_owned(self) -> MathInline<'static> {
55 let formula = Cow::Owned(self.0.into_owned());
56
57 MathInline::new(formula)
58 }
59}
60
61impl<'a> From<&'a str> for MathInline<'a> {
62 fn from(s: &'a str) -> Self {
63 Self::new(Cow::Borrowed(s))
64 }
65}
66
67impl From<String> for MathInline<'static> {
68 fn from(s: String) -> Self {
69 Self::new(Cow::Owned(s))
70 }
71}
72
73impl<'a> StrictEq for MathInline<'a> {
74 #[inline]
76 fn strict_eq(&self, other: &Self) -> bool {
77 self == other
78 }
79}