Skip to main content

RequireIndent

Enum RequireIndent 

Source
#[non_exhaustive]
pub enum RequireIndent { Unchecked, Divisible(usize), Even, Uniform(Option<usize>), }
Expand description

Requirements for indentation validation during YAML deserialization.

When set via options!, the deserializer validates every parser-reported indentation level against the chosen policy.

§Variants

VariantAccepts
UncheckedAny indentation (default)
Divisible(n)Indentation divisible by n
EvenEven indentation (0, 2, 4, …)
UniformConsistent indentation throughout the document

Important: if there are multiple documents in the YAML input, or added with !include, indentation requirements apply to all of them. For Uniform, indentation is required to be consistent across all included documents as well.

§Examples

§Enforcing even indentation

use serde_json::Value;

// This YAML uses 2-space indentation — accepted by `Even`.
let yaml = r#"
server:
  host: localhost
  port: 8080
"#;
let options = serde_saphyr::options! {
    require_indent: serde_saphyr::RequireIndent::Even,
};
let result = serde_saphyr::from_str_with_options::<Value>(yaml, options);
assert!(result.is_ok());
use serde_json::Value;

// This YAML uses 3-space indentation — rejected by `Even`.
let yaml = r#"
server:
   host: localhost
"#;
let options = serde_saphyr::options! {
    require_indent: serde_saphyr::RequireIndent::Even,
};
let result = serde_saphyr::from_str_with_options::<Value>(yaml, options);
assert!(result.is_err());

§Enforcing indentation divisible by 4

use serde_json::Value;

// 4-space indentation — accepted by `Divisible(4)`.
let yaml = r#"
database:
    host: db.local
    port: 5432
"#;
let options = serde_saphyr::options! {
    require_indent: serde_saphyr::RequireIndent::Divisible(4),
};
assert!(serde_saphyr::from_str_with_options::<Value>(yaml, options).is_ok());

§Enforcing uniform indentation

use serde_json::Value;

// Consistent 2-space indentation throughout.
let yaml = r#"
app:
  name: demo
  version: 1
"#;
let options = serde_saphyr::options! {
    require_indent: serde_saphyr::RequireIndent::Uniform(None),
};
assert!(serde_saphyr::from_str_with_options::<Value>(yaml, options).is_ok());

§YAML sample that triggers an indentation error

# With RequireIndent::Even, this document would fail:
config:
   debug: true    # 3-space indent — odd, rejected

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Unchecked

No indentation checking is performed.

§

Divisible(usize)

Indentation must be divisible by n.

§

Even

Indentation must be even.

§

Uniform(Option<usize>)

Indentation must be uniform throughout the document.

Implementations§

Source§

impl RequireIndent

Source

pub fn is_valid(&mut self, n: usize) -> Result<(), Error>

Checks whether the given indentation n is valid with respect to this requirement.

For Uniform, the first non-zero indentation encountered is remembered, and subsequent calls compare against that stored value.

Returns Ok(()) if valid, or an Error::IndentationError with Location::UNKNOWN. Deserialization entry points attach the source location before returning this error.

Trait Implementations§

Source§

impl Clone for RequireIndent

Source§

fn clone(&self) -> RequireIndent

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for RequireIndent

Source§

impl Debug for RequireIndent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RequireIndent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for RequireIndent

Source§

impl PartialEq for RequireIndent

Source§

fn eq(&self, other: &RequireIndent) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RequireIndent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.