typed_quote/tokens/
const_literal.rs1use core::fmt;
2
3use super::*;
4
5impl<T: HasConstLiteral + ?Sized> Default for ConstLiteral<T> {
6 fn default() -> Self {
7 Self::new()
8 }
9}
10
11impl<T: HasConstLiteral + ?Sized> ConstLiteral<T> {
12 pub const fn new() -> Self {
13 Self(PhantomData, NoSpan)
14 }
15}
16
17impl<T: HasConstLiteral + ?Sized, S: MaybeSpan> ConstLiteral<T, S> {
18 pub const fn as_literal(self) -> Literal<'static, S> {
19 Literal(T::LITERAL.0, self.1)
20 }
21}
22
23impl<T: HasConstLiteral + ?Sized, S: MaybeSpan> Copy for ConstLiteral<T, S> {}
24impl<T: HasConstLiteral + ?Sized, S: MaybeSpan> Clone for ConstLiteral<T, S> {
25 fn clone(&self) -> Self {
26 *self
27 }
28}
29
30impl<T: HasConstLiteral + ?Sized, S: MaybeSpan + fmt::Debug> fmt::Debug for ConstLiteral<T, S> {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 f.debug_tuple("ConstLiteral")
33 .field(&format_args!("{}", T::LITERAL.0))
34 .field(&self.1)
35 .finish()
36 }
37}
38
39impl<T: HasConstLiteral + ?Sized, S: MaybeSpan> sealed::IntoTokenTree for ConstLiteral<T, S> {}
40impl<T: HasConstLiteral + ?Sized, S: MaybeSpan> IntoTokenTree for ConstLiteral<T, S> {
41 crate::impl_into_token_tree!(|self| Literal(T::LITERAL.0, self.1).into_st());
42}
43
44impl<T: HasConstLiteral + ?Sized, S: MaybeSpan> sealed::ToTokenTree for ConstLiteral<T, S> {}
45impl<T: HasConstLiteral + ?Sized, S: MaybeSpan> ToTokenTree for ConstLiteral<T, S> {
46 crate::impl_to_token_tree! {copy}
47}
48
49impl<T: HasConstLiteral + ?Sized, S: MaybeSpan> sealed::IntoTokens for ConstLiteral<T, S> {}
50impl<T: HasConstLiteral + ?Sized, S: MaybeSpan> IntoTokens for ConstLiteral<T, S> {
51 crate::impl_into_tokens! {tt}
52}
53
54impl<T: HasConstLiteral + ?Sized, S: MaybeSpan> sealed::ToTokens for ConstLiteral<T, S> {}
55impl<T: HasConstLiteral + ?Sized, S: MaybeSpan> ToTokens for ConstLiteral<T, S> {
56 crate::impl_to_tokens! {copy}
57}
58
59impl<T: HasConstLiteral + ?Sized, SO: MaybeSpan> sealed::WithSpan for ConstLiteral<T, SO> {}
60impl<T: HasConstLiteral + ?Sized, SO: MaybeSpan> WithSpan for ConstLiteral<T, SO> {
61 type WithDefaultSpan<S: crate::Span> = ConstLiteral<T, SO::WithDefaultSpan<S>>;
62
63 fn with_default_span<S: crate::Span>(self, span: S) -> Self::WithDefaultSpan<S> {
64 ConstLiteral(self.0, self.1.with_default_span(span))
65 }
66
67 type WithReplacedSpan<S: crate::Span> = ConstLiteral<T, SO::WithReplacedSpan<S>>;
68
69 fn with_replaced_span<S: crate::Span>(self, span: S) -> Self::WithReplacedSpan<S> {
70 ConstLiteral(self.0, self.1.with_replaced_span(span))
71 }
72}
73
74impl<T: HasConstLiteral + ?Sized, SO: MaybeSpan> sealed::RefWithSpan for ConstLiteral<T, SO> {}
75impl<T: HasConstLiteral + ?Sized, SO: MaybeSpan> RefWithSpan for ConstLiteral<T, SO> {
76 crate::impl_ref_with_span! {copy}
77}