feat: implement StringLiteral macro
This commit is contained in:
24
string-literal/src/lib.rs
Normal file
24
string-literal/src/lib.rs
Normal 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 {}
|
||||
Reference in New Issue
Block a user