use crate::ser_error::Error;
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg(feature = "comments")]
pub enum CommentPosition {
Inline,
Above,
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub struct SerializerOptions {
pub empty_as_braces: bool,
pub indent_step: usize,
pub compact_list_indent: bool,
pub anchor_generator: Option<fn(usize) -> String>,
pub min_fold_chars: usize,
pub folded_wrap_chars: usize,
pub tagged_enums: bool,
pub prefer_block_scalars: bool,
pub quote_all: bool,
#[cfg(feature = "comments")]
pub comment_position: CommentPosition,
pub yaml_12: bool,
pub no_lang_directive: bool,
}
pub(crate) const MIN_FOLD_CHARS: usize = 32;
pub(crate) const FOLDED_WRAP_CHARS: usize = 80;
impl SerializerOptions {
pub(crate) const MAX_INDENT_STEP: usize = 64;
pub(crate) fn consistent(&self) -> Result<(), Error> {
if self.indent_step == 0 || self.indent_step > Self::MAX_INDENT_STEP {
return Err(Error::InvalidOptions(format!(
"indent_step must be in 1..={}",
Self::MAX_INDENT_STEP
)));
}
Ok(())
}
}
impl Default for SerializerOptions {
fn default() -> Self {
Self {
indent_step: 2,
compact_list_indent: true,
anchor_generator: None,
min_fold_chars: MIN_FOLD_CHARS,
folded_wrap_chars: FOLDED_WRAP_CHARS,
tagged_enums: false,
empty_as_braces: true,
prefer_block_scalars: true,
quote_all: false,
#[cfg(feature = "comments")]
comment_position: CommentPosition::Inline,
yaml_12: false,
no_lang_directive: false,
}
}
}