2019-04-11 15:23:14 -07:00
|
|
|
use crate::common::*;
|
2017-11-16 23:30:08 -08:00
|
|
|
|
2019-11-07 10:55:15 -08:00
|
|
|
/// A line fragment consisting either of…
|
2021-06-08 01:01:27 -07:00
|
|
|
#[derive(PartialEq, Debug, Clone)]
|
2019-11-07 10:55:15 -08:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|