pub(crate) struct BatchedErrors {
listed: Vec<(usize, String)>,
total: usize,
}Expand description
Bounded accumulator that folds per-element conversion failures into one
batched SexpError::InvalidValue, with the elements numbered as R
counts them (1-based).
Backs every vector conversion that walks its input: Vec<T> /
Vec<Option<T>> for a string-parsed type (ParsedRStr, #1143), the
numeric-coercion vector shells from_numeric_vec_with /
collect_coerced / coerce_slice_to_vec (#1192), tuples, factors,
the As*Vec markers and the optional integrations. Instead of bailing on
the first NA or failing element, they walk the whole vector and record
each failure here with its 0-based index; the message says where each one
is, (element 2).
Only the first BATCHED_ERROR_CAP failures are retained; every later
failure is counted but its 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.
The remainder is summarized as "; and N more".
Two foldings:
into_element_error: each entry is the failure’s reason (NA is not allowed,value out of range); entries with the same reason share one position list:NA is not allowed (elements 2, 4); value out of range (element 3).into_value_error: each entry is the offending value, listed with the positions after them, asAsNumericVecdoes:non-numeric value(s): "n/a", "<0.1" (elements 2, 5).
Neither names the Rust type: an argument’s conversion condition carries it
as e$rust_type (#1591).
Fields§
§listed: Vec<(usize, String)>(0-based index, reason or value) of the first BATCHED_ERROR_CAP
failures.
total: usizeImplementations§
Source§impl BatchedErrors
impl BatchedErrors
Sourcepub fn push(&mut self, index: usize, item: impl FnOnce() -> String)
pub fn push(&mut self, index: usize, item: impl FnOnce() -> String)
Record the failure of the element at 0-based index. item (its
reason or value) is evaluated, with whatever it allocates, only for the
first BATCHED_ERROR_CAP failures; later ones are counted for the
"and N more" tail but never built.
Sourcefn write_more_tail(&self, msg: &mut String)
fn write_more_tail(&self, msg: &mut String)
Append the "; and N more" tail when failures past the cap were counted.
Sourcepub fn into_element_error(self) -> SexpError
pub fn into_element_error(self) -> SexpError
Fold the recorded (index, reason) failures into one
SexpError::InvalidValue; see element_message.
Sourcepub fn element_message(&self) -> String
pub fn element_message(&self) -> String
The message behind into_element_error:
each distinct reason once, in the order it first occurred, followed by
the 1-based positions of the elements that failed with it:
NA is not allowed (elements 2, 4); value out of range (element 3)
Sourcepub fn into_value_error(self, what: &str) -> SexpError
pub fn into_value_error(self, what: &str) -> SexpError
Fold recorded (0-based index, offending value) pairs into one
SexpError::InvalidValue that shows the values and where they are:
<what> value(s): "n/a", "<0.1" (elements 2, 5)
Values are quoted (Rust Debug escaping, so invisible characters show),
and element numbers are 1-based, as R counts them. Past the cap, the
"; and N more" tail matches into_element_error.
Sourcefn value_message(&self, what: &str) -> String
fn value_message(&self, what: &str) -> String
The message behind into_value_error.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BatchedErrors
impl RefUnwindSafe for BatchedErrors
impl Send for BatchedErrors
impl Sync for BatchedErrors
impl Unpin for BatchedErrors
impl UnsafeUnpin for BatchedErrors
impl UnwindSafe for BatchedErrors
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreLayout§
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