just/src/string_literal.rs

30 lines
588 B
Rust
Raw Normal View History

use super::*;
2017-11-16 23:30:08 -08:00
2021-06-08 01:01:27 -07:00
#[derive(PartialEq, Debug, Clone)]
pub(crate) struct StringLiteral<'src> {
pub(crate) kind: StringKind,
pub(crate) raw: &'src str,
pub(crate) cooked: String,
2017-11-16 23:30:08 -08:00
}
impl Display for StringLiteral<'_> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(
f,
"{}{}{}",
self.kind.delimiter(),
self.raw,
self.kind.delimiter()
)
}
}
2021-11-17 00:07:48 -08:00
impl<'src> Serialize for StringLiteral<'src> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.cooked)
}
}