Skip to content

Commit

Permalink
Remove ArrowNativeType: FromStr (#2775)
Browse files Browse the repository at this point in the history
* Remove ArrowNativeType: FromStr

* Format
  • Loading branch information
tustvold committed Sep 24, 2022
1 parent 7c8080c commit d52cae0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 34 deletions.
10 changes: 1 addition & 9 deletions arrow-buffer/src/native.rs
Expand Up @@ -44,15 +44,7 @@ mod private {
///
/// Due to the above restrictions, this trait is sealed to prevent accidental misuse
pub trait ArrowNativeType:
std::fmt::Debug
+ Send
+ Sync
+ Copy
+ PartialOrd
+ std::str::FromStr
+ Default
+ private::Sealed
+ 'static
std::fmt::Debug + Send + Sync + Copy + PartialOrd + Default + private::Sealed + 'static
{
/// Convert native type from usize.
#[inline]
Expand Down
1 change: 1 addition & 0 deletions arrow/src/lib.rs
Expand Up @@ -117,6 +117,7 @@
//! fn parse_to_primitive<'a, T, I>(iter: I) -> PrimitiveArray<T>
//! where
//! T: ArrowPrimitiveType,
//! T::Native: FromStr,
//! I: IntoIterator<Item=&'a str>,
//! {
//! PrimitiveArray::from_iter(iter.into_iter().map(|val| T::Native::from_str(val).ok()))
Expand Down
47 changes: 22 additions & 25 deletions arrow/src/util/reader_parser.rs
Expand Up @@ -21,9 +21,7 @@ use crate::datatypes::*;
/// Specialized parsing implementations
/// used by csv and json reader
pub(crate) trait Parser: ArrowPrimitiveType {
fn parse(string: &str) -> Option<Self::Native> {
string.parse::<Self::Native>().ok()
}
fn parse(string: &str) -> Option<Self::Native>;

fn parse_formatted(string: &str, _format: &str) -> Option<Self::Native> {
Self::parse(string)
Expand All @@ -42,21 +40,23 @@ impl Parser for Float64Type {
}
}

impl Parser for UInt64Type {}

impl Parser for UInt32Type {}

impl Parser for UInt16Type {}

impl Parser for UInt8Type {}

impl Parser for Int64Type {}

impl Parser for Int32Type {}

impl Parser for Int16Type {}

impl Parser for Int8Type {}
macro_rules! parser_primitive {
($t:ty) => {
impl Parser for $t {
fn parse(string: &str) -> Option<Self::Native> {
string.parse::<Self::Native>().ok()
}
}
};
}
parser_primitive!(UInt64Type);
parser_primitive!(UInt32Type);
parser_primitive!(UInt16Type);
parser_primitive!(UInt8Type);
parser_primitive!(Int64Type);
parser_primitive!(Int32Type);
parser_primitive!(Int16Type);
parser_primitive!(Int8Type);

impl Parser for TimestampNanosecondType {
fn parse(string: &str) -> Option<i64> {
Expand Down Expand Up @@ -85,13 +85,10 @@ impl Parser for TimestampSecondType {
}
}

impl Parser for Time64NanosecondType {}

impl Parser for Time64MicrosecondType {}

impl Parser for Time32MillisecondType {}

impl Parser for Time32SecondType {}
parser_primitive!(Time64NanosecondType);
parser_primitive!(Time64MicrosecondType);
parser_primitive!(Time32MillisecondType);
parser_primitive!(Time32SecondType);

/// Number of days between 0001-01-01 and 1970-01-01
const EPOCH_DAYS_FROM_CE: i32 = 719_163;
Expand Down

0 comments on commit d52cae0

Please sign in to comment.