litext
A lightweight procedural macro library for extracting string literal contents from tokens, because doing that shouldn't bloat compilation time.
let value: String = litext!;
What is this?
Litext provides a macro to extract the inner text from a string literal token. You pass raw tokens to litext! and it gives you back the unwrapped string content without the quotes, optionally with the source span attached for precise diagnostics.
This is a proc-macro helper library. It is designed for proc-macro authors who need to extract string content from TokenStream input during macro expansion without the bloat.
Zero dependencies, tiny, built for proc-macro authors.
Installation
Add litext to your project:
Quick Start
Extract the string content as a String:
use ;
Extract with span information for precise diagnostics:
use ;
Features
- Extract string content from
TokenStreamtokens - Support for regular strings:
"hello world" - Support for raw strings:
r#"hello world"# - Support for raw strings with multiple hashes:
r##"hello #" world"## - Capture source spans via
litext!(input as LitStr)for precise diagnostics - Clear error messages for invalid inputs
- Absolutely zero dependencies
Requirements
- Rust 2024 edition
- A proc-macro crate (this library is for macro authors, not end users)
License
Licensed under either of:
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Cheers, RazkarStudio
© 2026 RazkarStudio. All rights reserved.