pub struct StyledText<'a> {
style: &'a str,
text: &'a str,
}
impl<'a> StyledText<'a> {
pub fn new(style: &'a str, text: &'a str) -> Self {
Self { style, text }
}
}
impl<'a> std::fmt::Debug for StyledText<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "<{}>{}</{}>", self.style, self.text, self.style)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_styled_text() {
let styled = StyledText {
style: "error",
text: "test",
};
let s = format!("{:?}", styled);
assert_eq!(s, "<error>test</error>");
}
}