litext 1.0.0

Just what you need for extracting string literal contents at compile time
Documentation
//! 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

mod str;
pub use str::*;

mod fromlit;
pub use fromlit::*;

mod totokens;
pub use totokens::*;