Skip to main content

BatchedErrors

Struct BatchedErrors 

Source
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, as AsNumericVec does: 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: usize

Implementations§

Source§

impl BatchedErrors

Source

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.

Source

pub fn is_empty(&self) -> bool

Whether any failure has been recorded.

Source

fn write_more_tail(&self, msg: &mut String)

Append the "; and N more" tail when failures past the cap were counted.

Source

pub fn into_element_error(self) -> SexpError

Fold the recorded (index, reason) failures into one SexpError::InvalidValue; see element_message.

Source

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)

Source

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.

Source

fn value_message(&self, what: &str) -> String

The message behind into_value_error.

Trait Implementations§

Source§

impl Default for BatchedErrors

Source§

fn default() -> Self

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

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> 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> RDefault for T
where T: Default,

Source§

fn r_default() -> T

Create a new instance with default values.
Source§

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

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. 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.

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