pomsky_syntax/exprs/
var.rs1use crate::Span;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct Variable {
5 pub name: String,
6 pub span: Span,
7}
8
9impl Variable {
10 pub(crate) fn new(name: &str, span: Span) -> Self {
11 Variable { name: name.to_string(), span }
12 }
13
14 #[cfg(feature = "dbg")]
15 pub(super) fn pretty_print(&self, buf: &mut crate::PrettyPrinter) {
16 buf.write(&self.name);
17 }
18}
19
20#[cfg(feature = "arbitrary")]
21impl arbitrary::Arbitrary<'_> for Variable {
22 fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
23 let name = super::arbitrary::Ident::create(u)?;
24 Ok(Variable { name, span: Span::arbitrary(u)? })
25 }
26
27 fn size_hint(depth: usize) -> (usize, Option<usize>) {
28 super::arbitrary::Ident::size_hint(depth)
29 }
30}