csv_sanity::transformer

Trait TransformResultHelper

Source
pub trait TransformResultHelper {
    // Provided methods
    fn present(value: &str) -> TransformResult { ... }
    fn excluded() -> TransformResult { ... }
    fn error(
        field_value: &str,
        field_name: &str,
        record_n: usize,
        reason: &str,
    ) -> TransformResult { ... }
}
Expand description

Helper trait with a few useful utility methods for constructing TransformResult.

Provided Methods§

Source

fn present(value: &str) -> TransformResult

Construct a TransformResult that represents a successful transformation of a CSV record’s field with a non-empty value.

Source

fn excluded() -> TransformResult

Construct a TransformResult that represents a successful tranformation of a CSV record’s field with an empty value.

Source

fn error( field_value: &str, field_name: &str, record_n: usize, reason: &str, ) -> TransformResult

Construct a TransformResult that represents a failed transformation of a CSV record’s field with a descritive error reason.

An error reason should be a short, single sentence without punctuation or capitization, e.g. “not a valid email address” instead of “The email address was invalid.”.

use csv_sanity::transformer::{
    TransformResult,
    TransformError,
    TransformResultHelper,
};

let result = TransformResult::error("jak,.@hot mail.com", "Email", 0, "not a valid email address");
assert_eq!(result, Err(TransformError {
    field_value: "jak,.@hot mail.com".to_string(),
    field_name: "Email".to_string(),
    record_n: 0,
    reason: "not a valid email address".to_string(),
}));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§