Skip to main content

BatchedErrors

Struct BatchedErrors 

Source
#[doc(hidden)]
pub struct BatchedErrors { listed: Vec<String>, total: usize, }
Expand description

Bounded accumulator that folds indexed per-element conversion failures into one batched SexpError::InvalidValue.

Backs the Vec<T> / Vec<Option<T>> arms of [try_from_sexp_via_str_parse!] (string-parse paths, #1143) and the numeric-coercion vector shells from_numeric_vec_with / collect_coerced / coerce_slice_to_vec (#1192): instead of bailing on the first NA or coercion failure, those walk the whole vector and record each failure here.

Only the first BATCHED_ERROR_CAP messages are retained; every later failure is counted but its message closure is never invoked. This keeps an all-failing N-element vector from materialising N Strings just to discard all but 10 — the memory held is bounded regardless of input size. On into_error the retained entries are joined with "; " and the remainder is summarized as "and N more".

Public (but hidden) because try_from_sexp_via_str_parse! is #[macro_export] and expands in downstream crates — not intended to be used directly.

Fields§

§listed: Vec<String>§total: usize

Implementations§

Source§

impl BatchedErrors

Source

pub fn push(&mut self, msg: impl FnOnce() -> String)

Record one per-element failure. msg is evaluated (and its String allocated) only for the first BATCHED_ERROR_CAP failures; later ones are counted for the "and N more" tail but never formatted.

Source

pub fn is_empty(&self) -> bool

Whether any failure has been recorded.

Source

pub fn into_error(self, container: &str) -> SexpError

Fold the recorded failures into one SexpError::InvalidValue under container (e.g. "Vec<u32>").

Trait Implementations§

Source§

impl Default for BatchedErrors

Source§

fn default() -> BatchedErrors

Returns the “default value” for a type. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 32 bytes