arrow::compute::kernels::cast_utils

Trait Parser

pub trait Parser: ArrowPrimitiveType {
    // Required method
    fn parse(string: &str) -> Option<Self::Native>;

    // Provided method
    fn parse_formatted(string: &str, _format: &str) -> Option<Self::Native> { ... }
}
Expand description

Specialized parsing implementations to convert strings to Arrow types.

This is used by csv and json reader and can be used directly as well.

§Example

To parse a string to a Date32Type:

use arrow_cast::parse::Parser;
use arrow_array::types::Date32Type;
let date = Date32Type::parse("2021-01-01").unwrap();
assert_eq!(date, 18628);

To parse a string to a TimestampNanosecondType:

use arrow_cast::parse::Parser;
use arrow_array::types::TimestampNanosecondType;
let ts = TimestampNanosecondType::parse("2021-01-01T00:00:00.123456789Z").unwrap();
assert_eq!(ts, 1609459200123456789);

Required Methods§

fn parse(string: &str) -> Option<Self::Native>

Parse a string to the native type

Provided Methods§

fn parse_formatted(string: &str, _format: &str) -> Option<Self::Native>

Parse a string to the native type with a format string

When not implemented, the format string is unused, and this method is equivalent to parse

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§