just/src/fragment.rs

27 lines
703 B
Rust
Raw Normal View History

use crate::common::*;
2017-11-16 23:30:08 -08:00
/// A line fragment consisting either of…
2021-06-08 01:01:27 -07:00
#[derive(PartialEq, Debug, Clone)]
pub(crate) enum Fragment<'src> {
/// …raw text…
Text { token: Token<'src> },
/// …an interpolation containing `expression`.
Interpolation { expression: Expression<'src> },
2017-11-16 23:30:08 -08:00
}
2021-11-17 00:07:48 -08:00
impl<'src> Serialize for Fragment<'src> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match self {
Self::Text { token } => serializer.serialize_str(token.lexeme()),
Self::Interpolation { expression } => {
let mut seq = serializer.serialize_seq(None)?;
seq.serialize_element(expression)?;
seq.end()
}
}
}
}