litext 0.3.0

Just what you need for extracting string literal contents at compile time
Documentation
  • Coverage
  • 100%
    7 out of 7 items documented0 out of 3 items with examples
  • Size
  • Source code size: 45.21 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.3 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 39s Average build duration of successful builds.
  • all releases: 40s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • razkar-studio

litext

Rust Version Crates.io Version docs.rs License MIT License Apache-2.0 Crates.io Downloads Deps.rs Maintenance

A lightweight procedural macro library for extracting string literal contents from tokens, because doing that shouldn't bloat compilation time.

let value: String = litext!(input);

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:

cargo add litext

Quick Start

Extract the string content as a String:

use litext::{litext, TokenStream};

pub fn my_macro(input: TokenStream) -> TokenStream {
    let content: String = litext!(input);
    // or, to be explicit:
    let content: String = litext!(input as String);
    // ... use content
}

Extract with span information for precise diagnostics:

use litext::{litext, LitStr, TokenStream};

pub fn my_macro(input: TokenStream) -> TokenStream {
    let lit: LitStr = litext!(input as LitStr);
    let value = lit.value(); // the string content
    let span = lit.span();   // where it appeared in source
    // ... use value and span
}

Features

  • Extract string content from TokenStream tokens
  • 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:

at your option.

Cheers, RazkarStudio

© 2026 RazkarStudio. All rights reserved.