m2_syn/token_stream/
punct.rs1use std::fmt::{Display, Formatter, Result};
2
3use crate::{Span, Spanned};
4
5use super::{ToTokens, TokenStream};
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash, Spanned)]
9pub struct Punct {
10 text: String,
11 span: Span,
12}
13
14impl Punct {
15 pub fn new(text: impl Into<String>, span: Span) -> Self {
16 Self {
17 text: text.into(),
18 span,
19 }
20 }
21
22 pub fn text(&self) -> &str {
23 &self.text
24 }
25}
26
27impl Display for Punct {
28 fn fmt(&self, formatter: &mut Formatter<'_>) -> Result {
29 formatter.write_str(self.text())
30 }
31}
32
33impl ToTokens for Punct {
34 fn to_tokens(&self, output: &mut TokenStream) {
35 output.push_punct(self.clone());
36 }
37}