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