typed_quote/tokens/
ident.rs1use super::*;
2
3#[cfg(any(feature = "proc-macro", feature = "proc-macro2"))]
4impl<'a, S: MaybeSpan> Ident<'a, S> {
5 fn to_raw(self) -> (bool, &'a str) {
6 match self.0.strip_prefix("r#") {
7 Some(ident) => (true, ident),
8 None => (false, self.0),
9 }
10 }
11}
12
13impl<'a, S: MaybeSpan> sealed::IntoTokenTree for Ident<'a, S> {}
14impl<'a, S: MaybeSpan> IntoTokenTree for Ident<'a, S> {
15 crate::impl_into_token_tree!(|self| {
16 let (is_raw, ident) = self.to_raw();
17 pm::TokenTree::Ident(if is_raw {
18 pm::Ident::new_raw(ident, self.1.into_st())
19 } else {
20 pm::Ident::new(ident, self.1.into_st())
21 })
22 });
23}
24
25impl<'a, S: MaybeSpan> sealed::ToTokenTree for Ident<'a, S> {}
26impl<'a, S: MaybeSpan> ToTokenTree for Ident<'a, S> {
27 crate::impl_to_token_tree! {copy}
28}
29
30impl<'a, S: MaybeSpan> sealed::IntoTokens for Ident<'a, S> {}
31impl<'a, S: MaybeSpan> IntoTokens for Ident<'a, S> {
32 crate::impl_into_tokens! {tt}
33}
34
35impl<'a, S: MaybeSpan> sealed::ToTokens for Ident<'a, S> {}
36impl<'a, S: MaybeSpan> ToTokens for Ident<'a, S> {
37 crate::impl_to_tokens! {tt}
38}
39impl<'a, S: MaybeSpan> sealed::WithSpan for Ident<'a, S> {}
40impl<'a, SO: MaybeSpan> WithSpan for Ident<'a, SO> {
41 type WithDefaultSpan<S: crate::Span> = Ident<'a, SO::WithDefaultSpan<S>>;
42 fn with_default_span<S: crate::Span>(self, span: S) -> Self::WithDefaultSpan<S> {
43 Ident(self.0, self.1.with_default_span(span))
44 }
45
46 type WithReplacedSpan<S: crate::Span> = Ident<'a, SO::WithReplacedSpan<S>>;
47
48 fn with_replaced_span<S: crate::Span>(self, span: S) -> Self::WithReplacedSpan<S> {
49 Ident(self.0, self.1.with_replaced_span(span))
50 }
51}
52
53impl<'a, S: MaybeSpan> sealed::RefWithSpan for Ident<'a, S> {}
54impl<'a, SO: MaybeSpan> RefWithSpan for Ident<'a, SO> {
55 crate::impl_ref_with_span!(copy);
56}