use deser_core::State;
use deser_core::adapters::Same;
use deser_core::hints::{Hint, Hinted};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ScalarStyle {
Plain,
SingleQuoted,
DoubleQuoted,
Literal,
Folded,
}
#[derive(Debug, Default, Clone)]
pub(crate) struct StyleHint(pub(crate) Option<ScalarStyle>);
impl ScalarStyle {
#[inline]
pub fn of(state: &State) -> Option<ScalarStyle> {
state.event::<StyleHint>().and_then(|x| x.0)
}
#[inline]
pub fn set(self, state: &mut State) {
state.event_mut::<StyleHint>().0 = Some(self);
}
}
macro_rules! style_adapter {
($(#[$meta:meta])* $alias:ident, $hint:ident, $style:expr) => {
#[doc = concat!("The [`Hint`] for [`", stringify!($style), "`].")]
pub struct $hint;
impl Hint for $hint {
#[inline]
fn set(state: &mut State) {
$style.set(state);
}
}
$(#[$meta])*
pub type $alias<A = Same> = Hinted<$hint, A>;
};
}
style_adapter!(
Plain,
PlainStyle,
ScalarStyle::Plain
);
style_adapter!(
SingleQuoted,
SingleQuotedStyle,
ScalarStyle::SingleQuoted
);
style_adapter!(
DoubleQuoted,
DoubleQuotedStyle,
ScalarStyle::DoubleQuoted
);
style_adapter!(
Literal,
LiteralStyle,
ScalarStyle::Literal
);
style_adapter!(
Folded,
FoldedStyle,
ScalarStyle::Folded
);