Skip to content

Commit 3c329a3

Browse files
Add Literal::raw_input
1 parent cf81440 commit 3c329a3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
44

55

66
## [Unreleased]
7+
- Add `Literal::raw_input`
78

89
## [0.5.0] - 2025-07-25
910
**Note**: this is supposed to be essentially a 1.0 release candidate.

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,24 @@ impl<B: Buffer> Literal<B> {
268268
Literal::CString(l) => l.suffix(),
269269
}
270270
}
271+
272+
/// Returns the raw input that was passed to `parse`.
273+
///
274+
/// This can be used to compare literals with different `Buffer` types.
275+
/// Note: this does not necessarily point to the same string buffer, in
276+
/// particular, bool literals just return a `&'static str`.
277+
pub fn raw_input(&self) -> &str {
278+
match self {
279+
Literal::Bool(l) => l.as_str(),
280+
Literal::Integer(l) => l.raw_input(),
281+
Literal::Float(l) => l.raw_input(),
282+
Literal::Char(l) => l.raw_input(),
283+
Literal::String(l) => l.raw_input(),
284+
Literal::Byte(l) => l.raw_input(),
285+
Literal::ByteString(l) => l.raw_input(),
286+
Literal::CString(l) => l.raw_input(),
287+
}
288+
}
271289
}
272290

273291
impl Literal<&str> {

0 commit comments

Comments
 (0)