datatypes::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.

Implementations on Foreign Types§

§

impl Parser for Date32Type

§

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

§

fn parse_formatted(string: &str, format: &str) -> Option<i32>

§

impl Parser for Date64Type

§

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

§

fn parse_formatted(string: &str, format: &str) -> Option<i64>

§

impl Parser for DurationMicrosecondType

§

fn parse( string: &str, ) -> Option<<DurationMicrosecondType as ArrowPrimitiveType>::Native>

§

impl Parser for DurationMillisecondType

§

fn parse( string: &str, ) -> Option<<DurationMillisecondType as ArrowPrimitiveType>::Native>

§

impl Parser for DurationNanosecondType

§

fn parse( string: &str, ) -> Option<<DurationNanosecondType as ArrowPrimitiveType>::Native>

§

impl Parser for DurationSecondType

§

fn parse( string: &str, ) -> Option<<DurationSecondType as ArrowPrimitiveType>::Native>

§

impl Parser for Float16Type

§

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

§

impl Parser for Float32Type

§

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

§

impl Parser for Float64Type

§

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

§

impl Parser for Int8Type

§

fn parse(string: &str) -> Option<<Int8Type as ArrowPrimitiveType>::Native>

§

impl Parser for Int16Type

§

fn parse(string: &str) -> Option<<Int16Type as ArrowPrimitiveType>::Native>

§

impl Parser for Int32Type

§

fn parse(string: &str) -> Option<<Int32Type as ArrowPrimitiveType>::Native>

§

impl Parser for Int64Type

§

fn parse(string: &str) -> Option<<Int64Type as ArrowPrimitiveType>::Native>

§

impl Parser for Time32MillisecondType

§

fn parse( string: &str, ) -> Option<<Time32MillisecondType as ArrowPrimitiveType>::Native>

§

fn parse_formatted( string: &str, format: &str, ) -> Option<<Time32MillisecondType as ArrowPrimitiveType>::Native>

§

impl Parser for Time32SecondType

§

fn parse( string: &str, ) -> Option<<Time32SecondType as ArrowPrimitiveType>::Native>

§

fn parse_formatted( string: &str, format: &str, ) -> Option<<Time32SecondType as ArrowPrimitiveType>::Native>

§

impl Parser for Time64MicrosecondType

§

fn parse( string: &str, ) -> Option<<Time64MicrosecondType as ArrowPrimitiveType>::Native>

§

fn parse_formatted( string: &str, format: &str, ) -> Option<<Time64MicrosecondType as ArrowPrimitiveType>::Native>

§

impl Parser for Time64NanosecondType

§

fn parse( string: &str, ) -> Option<<Time64NanosecondType as ArrowPrimitiveType>::Native>

§

fn parse_formatted( string: &str, format: &str, ) -> Option<<Time64NanosecondType as ArrowPrimitiveType>::Native>

§

impl Parser for TimestampMicrosecondType

§

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

§

impl Parser for TimestampMillisecondType

§

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

§

impl Parser for TimestampNanosecondType

§

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

§

impl Parser for TimestampSecondType

§

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

§

impl Parser for UInt8Type

§

fn parse(string: &str) -> Option<<UInt8Type as ArrowPrimitiveType>::Native>

§

impl Parser for UInt16Type

§

fn parse(string: &str) -> Option<<UInt16Type as ArrowPrimitiveType>::Native>

§

impl Parser for UInt32Type

§

fn parse(string: &str) -> Option<<UInt32Type as ArrowPrimitiveType>::Native>

§

impl Parser for UInt64Type

§

fn parse(string: &str) -> Option<<UInt64Type as ArrowPrimitiveType>::Native>

Implementors§