arrow_cast::parse

Trait Parser

Source
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§

Source

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

Parse a string to the native type

Provided Methods§

Source

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§

Source§

impl Parser for Date32Type

Source§

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

Source§

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

Source§

impl Parser for Date64Type

Source§

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

Source§

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

Source§

impl Parser for DurationMicrosecondType

Source§

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

Source§

impl Parser for DurationMillisecondType

Source§

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

Source§

impl Parser for DurationNanosecondType

Source§

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

Source§

impl Parser for DurationSecondType

Source§

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

Source§

impl Parser for Float16Type

Source§

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

Source§

impl Parser for Float32Type

Source§

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

Source§

impl Parser for Float64Type

Source§

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

Source§

impl Parser for Int8Type

Source§

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

Source§

impl Parser for Int16Type

Source§

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

Source§

impl Parser for Int32Type

Source§

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

Source§

impl Parser for Int64Type

Source§

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

Source§

impl Parser for Time32MillisecondType

Source§

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

Source§

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

Source§

impl Parser for Time32SecondType

Source§

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

Source§

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

Source§

impl Parser for Time64MicrosecondType

Source§

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

Source§

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

Source§

impl Parser for Time64NanosecondType

Source§

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

Source§

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

Source§

impl Parser for TimestampMicrosecondType

Source§

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

Source§

impl Parser for TimestampMillisecondType

Source§

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

Source§

impl Parser for TimestampNanosecondType

Source§

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

Source§

impl Parser for TimestampSecondType

Source§

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

Source§

impl Parser for UInt8Type

Source§

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

Source§

impl Parser for UInt16Type

Source§

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

Source§

impl Parser for UInt32Type

Source§

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

Source§

impl Parser for UInt64Type

Source§

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

Implementors§