moxy_token/lit/
verbatim.rs1use crate::lit::Lit;
2use crate::{Span, Spanner};
3
4#[derive(Debug, Clone)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(into = "String"))]
6pub struct LitVerbatim {
7 repr: Box<str>,
8 span: Span,
9}
10
11impl LitVerbatim {
12 #[inline]
13 pub fn new(repr: &str, span: Span) -> Self {
14 Self { repr: repr.into(), span }
15 }
16
17 #[inline]
18 pub fn repr(&self) -> &str {
19 &self.repr
20 }
21
22 #[inline]
23 pub fn span(&self) -> Span {
24 self.span
25 }
26
27 #[inline]
28 pub fn set_span(&mut self, span: Span) {
29 self.span = span;
30 }
31}
32
33impl PartialEq for LitVerbatim {
34 fn eq(&self, other: &Self) -> bool {
35 self.repr == other.repr
36 }
37}
38
39impl Eq for LitVerbatim {}
40
41impl std::hash::Hash for LitVerbatim {
42 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
43 self.repr.hash(state);
44 }
45}
46
47impl std::fmt::Display for LitVerbatim {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 f.write_str(&self.repr)
50 }
51}
52
53impl Spanner for LitVerbatim {
54 fn span(&self) -> Span {
55 self.span
56 }
57}
58
59impl From<LitVerbatim> for Lit {
60 fn from(value: LitVerbatim) -> Self {
61 Self::Verbatim(value)
62 }
63}
64
65#[cfg(feature = "serde")]
66impl From<LitVerbatim> for String {
67 fn from(value: LitVerbatim) -> Self {
68 value.repr.into_string()
69 }
70}