litrs
Parse and inspect Rust literals (i.e. tokens in the Rust programming language representing fixed values). Particularly useful for proc macros, but can also be used outside of a proc-macro context.
1.0.0
143M downloads/mo
#632 most downloaded on crates.io
LukasKalbertodt/litrs
What this package is like to depend on
Last release 10 months ago
20 Oct 2025
Release timing varies
gaps range from 1 weeks to 1.8 years
Nearly every release is documented
notes for 13 of 13 stable releases
Nothing withdrawn
no release was ever pulled
5 years old
13 releases · first in 2021
1 release in the last 12 months
see the full history below
Release timeline
13 releases · May 2021 to Oct 2025Releases
latest 13-
1.0.020 Oct 2025Release notes
Open source →As announced, this is basically just v0.5. I'm really happy to finally have
litrsin v1.x state, as the library was already fit for production usage for a long time. Now the version reflects that.- Breaking: Mark
Literalas#[non_exhaustive] - Document semver guarantees
Release notes
Open source →As announced, this is basically just v0.5. I'm really happy to finally have
litrsin v1.x state, as the library was already fit for production usage for a long time. Now the version reflects that.- Breaking: Mark
Literalas#[non_exhaustive] - Document semver guarantees
- Breaking: Mark
-
0.5.101 Aug 2025 -
0.5.025 Jul 2025Release notes
Open source →Note: this is supposed to be essentially a 1.0 release candidate. If there are no problems with this release, it will be released as 1.0 after some time.
- Breaking Bump MSRC from 1.54 to 1.56
- Breaking: Remove
proc-macro2from default features - Breaking: Make
StringLit<String>::into_valuereturnStringinstead ofCow<'static, str>.
MakeByteStringLit<String>::into_valuereturnVec<u8>instead ofCow<'static, [u8]>. - Add support for C string literals
- Limit number of
#as delimiter of raw string literals to 256 (to align with spec) - Fix license in
Cargo.tomlto use proper SPDX format (in #19, thanks @atouchet) - Fix error span for
InvalidStartOfUnicodeEscapeerrors
Release notes
Open source →Note: this is supposed to be essentially a 1.0 release candidate. If there are no problems with this release, it will be released as 1.0 after some time.
- Breaking Bump MSRC from 1.54 to 1.56
- Breaking: Remove
proc-macro2from default features - Breaking: Make
StringLit<String>::into_valuereturnStringinstead ofCow<'static, str>. MakeByteStringLit<String>::into_valuereturnVec<u8>instead ofCow<'static, [u8]>. - Add support for C string literals (also breaking due to new enum variant)
- Limit number of
#as delimiter of raw string literals to 256 (to align with spec) - Fix license in
Cargo.tomlto use proper SPDX format (in #19, thanks @atouchet) - Fix error span for
InvalidStartOfUnicodeEscapeerrors
-
0.4.225 Jul 2025Release notes
Open source →- Fix incorrect byte string value with non-ASCII
\xHHbyte string escapesByteStringLit::parse(r#"b"\xff""#).unwrap().value()would return[0xc3, 0xbf]instead of[0xff].
- Remove CR LF normalization to align with spec
- This is technically a breaking change, but released with a minor version bump as it just aligns with the specification. It is extremely unlikely to affect any real world use case.
- Fix incorrect error span for out-of-range Unicode escapes
Release notes
Open source →- Fix incorrect byte string value with non-ASCII
\xHHbyte string escapesByteStringLit::parse(r#"b"\xff""#).unwrap().value()would return[0xc3, 0xbf]instead of[0xff].
- Remove CR LF normalization to align with spec
- This is technically a breaking change, but released with a minor version bump as it just aligns with the specification. It is extremely unlikely to affect any real world use case.
- Fix incorrect error span for out-of-range Unicode escapes
- Fix incorrect byte string value with non-ASCII
-
0.4.118 Oct 2023Release notes
Open source →- Fixed incorrectly labeling
27f32a float literals in docs. - Added hint to integer literal docs about parsing as
u128.
Release notes
Open source →- Fixed incorrectly labeling
27f32a float literals in docs. - Added hint to integer literal docs about parsing as
u128.
- Fixed incorrectly labeling
-
0.4.005 Mar 2023Release notes
Open source →Added
- Add ability to parse literals with arbitrary suffixes (e.g.
"foo"blaor23px) - Add
suffix()method to all literal types exceptBoolLit - Add
IntegerBase::value - Add
from_suffixandsuffixmethods toFloatTypeandIntegerType - Add
FromStrandDisplayimpls toFloatTypeandIntegerType
Changed
- Breaking: Mark
FloatTypeandIntegerTypeas#[non_exhaustive] - Breaking: Fix integer parsing for cases like
27f32.Literal::parse
andIntegerLit::parsewill both identify this as an integer literal. - Breaking: Fix float parsing by correctly rejecting inputs like
27f32. A
float literal must have a period OR an exponent part, according to the spec.
Previously decimal integers were accepted inFloatLit::parse. - Improved some parts of the docs
Removed
- Breaking: Remove
OwnedLiteralandSharedLiteral
Release notes
Open source →Added
- Add ability to parse literals with arbitrary suffixes (e.g.
"foo"blaor23px) - Add
suffix()method to all literal types exceptBoolLit - Add
IntegerBase::value - Add
from_suffixandsuffixmethods toFloatTypeandIntegerType - Add
FromStrandDisplayimpls toFloatTypeandIntegerType
Changed
- Breaking: Mark
FloatTypeandIntegerTypeas#[non_exhaustive] - Breaking: Fix integer parsing for cases like
27f32.Literal::parseandIntegerLit::parsewill both identify this as an integer literal. - Breaking: Fix float parsing by correctly rejecting inputs like
27f32. A float literal must have a period OR an exponent part, according to the spec. Previously decimal integers were accepted inFloatLit::parse. - Improved some parts of the docs
Removed
- Breaking: Remove
OwnedLiteralandSharedLiteral
- Add ability to parse literals with arbitrary suffixes (e.g.
-
0.3.019 Dec 2022Release notes
Open source →Breaking
- Bump MSRV (minimal supported Rust version) to 1.54
Added
- Add
raw_inputandinto_raw_inputto non-bool*Littypes - Add
impl From<*Lit> for pm::Literal(for non-bool literals) - Add
impl From<BoolLit> for pm::Ident
Fixed
- Fix link to reference and clarify bool literals (#7)
Internals
- Move lots of parsing code into non-generic functions (this hopefully reduces compile times)
- To implement
[into_]raw_inputfor integer and float literals, their
internals were changed a bit so that they store the full input string now.
Release notes
Open source →Breaking
- Bump MSRV (minimal supported Rust version) to 1.54
Added
- Add
raw_inputandinto_raw_inputto non-bool*Littypes - Add
impl From<*Lit> for pm::Literal(for non-bool literals) - Add
impl From<BoolLit> for pm::Ident
Fixed
- Fix link to reference and clarify bool literals (#7)
Internals
- Move lots of parsing code into non-generic functions (this hopefully reduces compile times)
- To implement
[into_]raw_inputfor integer and float literals, their internals were changed a bit so that they store the full input string now.
-
0.2.309 Jun 2021 -
0.2.209 Jun 2021Release notes
Open source →Changed
- Fixed (byte) string literal parsing by:
- Correctly handling "string continue" sequences
- Correctly converting
\n\rinto\n
- Fixed (byte) string literal parsing by:
-
0.2.104 Jun 2021Release notes
Open source →Changed
- Fixed the
expectedvalue of the error returned fromTryFrom<TokenTree>impls in some cases
- Fixed the
-
0.2.028 May 2021Release notes
Open source →Changed
- Breaking: rename
ErrortoParseError. That describes its purpose more closely and is particular useful now that other error types exist in the library.
Removed
- Breaking: remove
proc-macrofeature and instead offer the correspondingimpls unconditionally. Since the feature didn't enable/disable a dependency (proc-macrois a compiler provided crate) and since apparently it works fine inno_stdenvironments, I dropped this feature. I don't currently see a reason why the corresponding impls should be conditional.
Added
TryFrom<TokenTree> for litrs::LiteralimplsFrom<*Lit> for litrs::LiteralimplsTryFrom<proc_macro[2]::Literal> for *LitTryFrom<TokenTree> for *LitInvalidTokenerror type for all newTryFromimpls
- Breaking: rename
-
0.1.125 May 2021Release notes
Open source →Added
Fromimpls to create aLiteralfrom references to proc-macro literal types:From<&proc_macro::Literal>From<&proc_macro2::Literal>
- Better examples in README and repository
-
0.1.024 May 2021