ezno_parser/
marker.rs

1use std::marker::PhantomData;
2
3/// Places in the AST which are either partial OR will recieve data from the generator
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub struct Marker<T>(pub u8, pub PhantomData<T>);
6
7#[cfg_attr(target_family = "wasm", wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section))]
8#[allow(dead_code)]
9const TYPES: &str = r"
10	type Marker<T> = number;
11";
12
13pub const MARKER: &str = "EZNO_GENERATOR_SLOT";
14
15#[cfg(feature = "serde-serialize")]
16impl<T> serde::Serialize for Marker<T> {
17	fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
18	where
19		S: serde::Serializer,
20	{
21		self.0.serialize(serializer)
22	}
23}
24
25// Custom implementation used by the generator to interpolate nodes
26#[cfg(feature = "self-rust-tokenize")]
27impl<T> self_rust_tokenize::SelfRustTokenize for Marker<T> {
28	fn append_to_token_stream(
29		&self,
30		token_stream: &mut self_rust_tokenize::proc_macro2::TokenStream,
31	) {
32		use self_rust_tokenize::proc_macro2::{Ident, Span};
33		let token = Ident::new(&format!("_marker_{}", self.0), Span::call_site());
34		token_stream.extend(self_rust_tokenize::quote!(ezno_parser::IntoAST::into_ast(#token)));
35	}
36}