1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Types and traits for handling Rust literals in procedural macros.
//!
//! This module provides span-aware literal types, the [`FromLit`] trait for
//! extracting values from proc-macro tokens, and the [`ToTokens`] trait for
//! converting them back into token streams. These types bundle the parsed value
//! with its source location, enabling precise error reporting.
//!
//! ## Span-Aware Types
//!
//! When you need to emit error messages that point to the exact location of a
//! literal in the user's code, use the span-aware types instead of plain values:
//!
//! | Plain Type | Span-Aware Type | Use Case |
//! |------------|-----------------|----------|
//! | `String` | [`LitStr`] | String literals with span tracking |
//! | `i8`–`i128`, `isize`, `usize` | [`LitInt<T>`] | Integer literals with span tracking |
//! | `f32`, `f64` | [`LitFloat<T>`] | Float literals with span tracking |
//! | `bool` | [`LitBool`] | Boolean literals with span tracking |
//! | `char` | [`LitChar`] | Character literals with span tracking |
//! | `u8` | [`LitByte`] | Byte literals (`b'a'`) with span tracking |
//! | `Vec<u8>` | [`LitByteStr`] | Byte string literals (`b"..."`) with span tracking |
//! | `CString` | [`LitCStr`] | C string literals (`c"..."`) with span tracking |
//!
//! ## Round-Tripping with `ToTokens`
//!
//! All span-aware types implement [`ToTokens`], allowing you to extract a literal,
//! inspect or validate it, and then emit it back into your macro output:
//!
//! ```ignore
//! use litext::literal::{LitStr, ToTokens};
//!
//! let lit: LitStr = extract(input)?;
//! if lit.value().is_empty() {
//! return Err(comperr::error(lit.span(), "string cannot be empty"));
//! }
//! // Emit the literal back with its original span
//! let output: TokenStream = lit.to_token_stream();
//! ```
//!
//! ## Example
//!
//! ```ignore
//! use litext::literal::{LitStr, FromLit};
//!
//! fn validate_string(input: TokenStream) -> Result<LitStr, TokenStream> {
//! let lit = extract::<LitStr>(input)?;
//!
//! if lit.value().is_empty() {
//! // Emit error at the exact location of the literal
//! return Err(comperr::error(lit.span(), "string cannot be empty"));
//! }
//!
//! Ok(lit)
//! }
//! ```
//!
//! ## See Also
//!
//! - [`FromLit`] for implementing custom literal extraction
//! - [`ToTokens`] for converting literals back to tokens
//! - The parent crate's [`extract`](crate::extract) function
pub use str::*;
pub use *;
pub use *;