feat: implement StringLiteral macro

This commit is contained in:
J / Jacob Babich
2026-07-09 22:20:24 -04:00
parent d6ad9972c7
commit 0565624599
10 changed files with 209 additions and 121 deletions

24
string-literal/src/lib.rs Normal file
View File

@@ -0,0 +1,24 @@
use std::fmt::{Debug, Display};
#[cfg(feature = "macros")]
pub use string_literal_macros::StringLiteral;
#[derive(Debug, Clone)]
pub struct WrongLiteralError<S> {
pub actual: String,
pub expected: S,
}
impl<S> Display for WrongLiteralError<S>
where
S: AsRef<str>,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self { actual, expected } = self;
let expected_str = expected.as_ref();
write!(f, "expected {expected_str:?} but got {actual:?}")
}
}
impl<S> std::error::Error for WrongLiteralError<S> where WrongLiteralError<S>: Debug + Display {}