use crate::ser_error::Error;
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CommentPosition {
Inline,
Above,
}
#[derive(Clone, Copy)]
pub struct SerializerOptions {
#[deprecated(
note = "Direct construction of `SerializerOptions` will be disabled from 1.0.0, use macro `ser_options!`"
)]
pub empty_as_braces: bool,
#[deprecated(
note = "Direct construction of `SerializerOptions` will be disabled from 1.0.0, use macro `ser_options!`"
)]
pub indent_step: usize,
#[deprecated(
note = "Direct construction of `SerializerOptions` will be disabled from 1.0.0, use macro `ser_options!`"
)]
pub compact_list_indent: bool,
#[deprecated(
note = "Direct construction of `SerializerOptions` will be disabled from 1.0.0, use macro `ser_options!`"
)]
pub anchor_generator: Option<fn(usize) -> String>,
#[deprecated(
note = "Direct construction of `SerializerOptions` will be disabled from 1.0.0, use macro `ser_options!`"
)]
pub min_fold_chars: usize,
#[deprecated(
note = "Direct construction of `SerializerOptions` will be disabled from 1.0.0, use macro `ser_options!`"
)]
pub folded_wrap_chars: usize,
#[deprecated(
note = "Direct construction of `SerializerOptions` will be disabled from 1.0.0, use macro `ser_options!`"
)]
pub tagged_enums: bool,
#[deprecated(
note = "Direct construction of `SerializerOptions` will be disabled from 1.0.0, use macro `ser_options!`"
)]
pub prefer_block_scalars: bool,
#[deprecated(
note = "Direct construction of `SerializerOptions` will be disabled from 1.0.0, use macro `ser_options!`"
)]
pub quote_all: bool,
#[deprecated(
note = "Direct construction of `SerializerOptions` will be disabled from 1.0.0, use macro `ser_options!`"
)]
pub comment_position: CommentPosition,
#[deprecated(
note = "Direct construction of `SerializerOptions` will be disabled from 1.0.0, use macro `ser_options!`"
)]
pub yaml_12: bool,
}
pub(crate) const MIN_FOLD_CHARS: usize = 32;
pub(crate) const FOLDED_WRAP_CHARS: usize = 80;
impl SerializerOptions {
#[allow(deprecated)]
pub(crate) fn consistent(&self) -> Result<(), Error> {
if self.indent_step == 0 {
return Err(Error::InvalidOptions(
"Invalid indent step must be positive".to_string(),
));
}
Ok(())
}
}
impl Default for SerializerOptions {
#[allow(deprecated)]
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,
comment_position: CommentPosition::Inline,
yaml_12: false,
}
}
}