Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the Ion value types to the types module #543

Merged
merged 3 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/binary/binary_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use crate::binary::raw_binary_writer::{RawBinaryWriter, RawBinaryWriterBuilder};
use crate::constants::v1_0::system_symbol_ids;
use crate::raw_symbol_token_ref::{AsRawSymbolTokenRef, RawSymbolTokenRef};
use crate::result::{illegal_operation, IonResult};
use crate::types::decimal::Decimal;
use crate::types::timestamp::Timestamp;
use crate::types::Decimal;
use crate::types::SymbolId;
use crate::types::Timestamp;
use crate::writer::IonWriter;
use crate::{Int, IonType, SymbolTable};
use crate::{types::Int, types::IonType, SymbolTable};
use delegate::delegate;
use std::io::Write;

Expand Down
6 changes: 1 addition & 5 deletions src/binary/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ use crate::{
int::DecodedInt, raw_binary_writer::MAX_INLINE_LENGTH, var_int::VarInt, var_uint::VarUInt,
},
result::IonResult,
types::{
coefficient::{Coefficient, Sign},
decimal::Decimal,
integer::UInt,
},
types::{Coefficient, Decimal, Sign, UInt},
IonError,
};

Expand Down
10 changes: 5 additions & 5 deletions src/binary/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::mem;

use crate::data_source::IonDataSource;
use crate::result::{decoding_error, IonResult};
use crate::types::coefficient;
use crate::types::coefficient::Coefficient;
use crate::Int;
use crate::types;
use crate::types::Coefficient;
use crate::types::Int;
use num_bigint::{BigInt, Sign};
use num_traits::Zero;
use std::io::Write;
Expand Down Expand Up @@ -196,7 +196,7 @@ impl From<DecodedInt> for Coefficient {
is_negative,
.. // ignore `size_in_bytes`
} = int;
use coefficient::Sign::{Negative, Positive};
use types::Sign::{Negative, Positive};
let sign = if is_negative { Negative } else { Positive };
Coefficient::new(sign, value)
}
Expand All @@ -206,7 +206,7 @@ impl From<DecodedInt> for Coefficient {
mod tests {
use super::*;
use crate::result::IonResult;
use crate::Int;
use crate::types::Int;
use std::io;
use std::io::Cursor;

Expand Down
4 changes: 2 additions & 2 deletions src/binary/non_blocking/binary_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::binary::uint::DecodedUInt;
use crate::binary::var_int::VarInt;
use crate::binary::var_uint::VarUInt;
use crate::result::{decoding_error, incomplete_data_error, incomplete_data_error_raw};
use crate::types::integer::UInt;
use crate::{Int, IonResult, IonType};
use crate::types::UInt;
use crate::{types::Int, IonResult, IonType};
popematt marked this conversation as resolved.
Show resolved Hide resolved
use num_bigint::{BigInt, BigUint, Sign};
use std::io::Read;
use std::mem;
Expand Down
10 changes: 5 additions & 5 deletions src/binary/non_blocking/raw_binary_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ use crate::binary::non_blocking::type_descriptor::{Header, TypeDescriptor};
use crate::binary::uint::DecodedUInt;
use crate::binary::var_uint::VarUInt;
use crate::binary::IonTypeCode;
use crate::element::{Blob, Clob};
use crate::result::{
decoding_error, decoding_error_raw, illegal_operation, illegal_operation_raw,
incomplete_data_error,
};
use crate::types::integer::IntAccess;
use crate::types::string::Str;
use crate::types::IntAccess;
use crate::types::Str;
use crate::types::SymbolId;
use crate::types::{Blob, Clob};
use crate::{
raw_reader::BufferedRawReader, Decimal, Int, IonReader, IonResult, IonType, RawStreamItem,
RawSymbolToken, Timestamp,
raw_reader::BufferedRawReader, types::Decimal, Int, IonReader, IonResult, IonType,
Comment on lines +12 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consolidate these crate::types::{...} imports, especially the one that says types::Decimal.

RawStreamItem, RawSymbolToken, Timestamp,
};
use bytes::{BigEndian, Buf, ByteOrder};
use num_bigint::BigUint;
Expand Down
8 changes: 4 additions & 4 deletions src/binary/raw_binary_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::binary::uint::DecodedUInt;
use crate::binary::var_uint::VarUInt;
use crate::raw_symbol_token_ref::{AsRawSymbolTokenRef, RawSymbolTokenRef};
use crate::result::{illegal_operation, IonResult};
use crate::types::decimal::Decimal;
use crate::types::timestamp::Timestamp;
use crate::types::Decimal;
use crate::types::Timestamp;
use crate::types::{ContainerType, SymbolId};
Comment on lines +14 to 16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consolidate these.

use crate::writer::IonWriter;
use crate::{Int, IonType};
Expand Down Expand Up @@ -910,10 +910,10 @@ mod writer_tests {
use rstest::*;

use super::*;
use crate::element::{Blob, Clob};
use crate::raw_symbol_token::{local_sid_token, RawSymbolToken};
use crate::reader::{Reader, ReaderBuilder};
use crate::symbol::Symbol;
use crate::types::Symbol;
use crate::types::{Blob, Clob};
Comment on lines +915 to +916
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consolidate these.

use crate::IonReader;
use num_bigint::BigInt;
use num_traits::Float;
Expand Down
5 changes: 1 addition & 4 deletions src/binary/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use crate::{
var_uint::VarUInt,
},
result::IonResult,
types::{
decimal::Decimal,
timestamp::{Mantissa, Precision, Timestamp},
},
types::{Decimal, Mantissa, Precision, Timestamp},
};

const MAX_TIMESTAMP_LENGTH: usize = 32;
Expand Down
2 changes: 1 addition & 1 deletion src/binary/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::mem;

use crate::data_source::IonDataSource;
use crate::result::{decoding_error, IonResult};
use crate::types::integer::{Int, UInt};
use crate::types::{Int, UInt};

// This limit is used for stack-allocating buffer space to encode/decode UInts.
const UINT_STACK_BUFFER_SIZE: usize = 16;
Expand Down
2 changes: 1 addition & 1 deletion src/blocking_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::raw_reader::BufferedRawReader;
use crate::result::IonResult;
use crate::stream_reader::IonReader;
use crate::text::non_blocking::raw_text_reader::RawTextReader;
use crate::types::timestamp::Timestamp;
use crate::types::Timestamp;
use crate::{Decimal, Int, IonError, IonType, Str};

pub type BlockingRawTextReader<T> = BlockingRawReader<RawTextReader<Vec<u8>>, T>;
Expand Down
2 changes: 1 addition & 1 deletion src/element/annotations.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::element::iterators::{AnnotationsIntoIter, SymbolsIterator};
use crate::ion_data::IonOrd;
use crate::types::iterators::{AnnotationsIntoIter, SymbolsIterator};
use crate::Symbol;
use std::cmp::Ordering;

Expand Down
4 changes: 2 additions & 2 deletions src/element/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ macro_rules! ion_struct {
}};
}

use crate::element::list::List;
use crate::element::sexp::SExp;
use crate::types::List;
use crate::types::SExp;
pub use ion_list;
pub use ion_sexp;
pub use ion_struct;
Expand Down
6 changes: 3 additions & 3 deletions src/element/element_stream_reader.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::result::{decoding_error, illegal_operation, illegal_operation_raw};
use crate::text::parent_container::ParentContainer;

use crate::element::iterators::SymbolsIterator;
use crate::element::{Blob, Clob, Element};
use crate::types::iterators::SymbolsIterator;
use crate::{
Decimal, Int, IonError, IonReader, IonResult, IonType, Str, StreamItem, Symbol, Timestamp,
};
Expand Down Expand Up @@ -361,8 +361,8 @@ mod reader_tests {
use super::*;
use crate::result::IonResult;
use crate::stream_reader::IonReader;
use crate::types::decimal::Decimal;
use crate::types::timestamp::Timestamp;
use crate::types::Decimal;
use crate::types::Timestamp;

use crate::IonType;

Expand Down
23 changes: 8 additions & 15 deletions src/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,19 @@ use std::fmt::{Display, Formatter};

mod annotations;
pub mod builders;
mod bytes;
mod element_stream_reader;
mod iterators;
mod list;
mod lob;
pub mod reader;
mod sequence;
mod sexp;
mod r#struct;
pub mod writer;

// Re-export the Value variant types and traits so they can be accessed directly from this module.
pub use self::bytes::Bytes;
pub use crate::types::Bytes;
pub use crate::types::{Blob, Clob};
pub use annotations::{Annotations, IntoAnnotations};
pub use lob::{Blob, Clob};

pub use list::List;
pub use r#struct::Struct;
pub use sequence::Sequence;
pub use sexp::SExp;
pub use crate::types::List;
pub use crate::types::SExp;
pub use crate::types::Sequence;
pub use crate::types::Struct;
Comment on lines 33 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would at least put these together so they rustfmt together.


impl IonEq for Value {
fn ion_eq(&self, other: &Self) -> bool {
Expand Down Expand Up @@ -614,7 +607,7 @@ where
#[cfg(test)]
mod tests {
use crate::element::annotations::IntoAnnotations;
use crate::types::timestamp::Timestamp;
use crate::types::Timestamp;
use crate::{ion_list, ion_sexp, ion_struct, Decimal, Int, IonType, Symbol};
use chrono::*;
use rstest::*;
Expand Down Expand Up @@ -864,7 +857,7 @@ mod tests {
}

use crate::element::{Annotations, Element, IntoAnnotatedElement, Struct};
use crate::types::integer::IntAccess;
use crate::types::IntAccess;
use num_bigint::BigInt;
use std::collections::HashSet;
use std::str::FromStr;
Expand Down
4 changes: 2 additions & 2 deletions src/element/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ mod reader_tests {
use crate::element::Value::*;
use crate::element::{Element, IntoAnnotatedElement};
use crate::ion_data::IonEq;
use crate::types::integer::Int;
use crate::types::timestamp::Timestamp as TS;
use crate::types::Int;
use crate::types::Timestamp as TS;
use crate::{IonType, Symbol};
use bigdecimal::BigDecimal;
use num_bigint::BigInt;
Expand Down
6 changes: 3 additions & 3 deletions src/ion_hash/representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use crate::binary::{self, decimal::DecimalBinaryEncoder, timestamp::TimestampBin
use crate::element::{Element, Sequence, Struct};
use crate::ion_hash::element_hasher::ElementHasher;
use crate::ion_hash::type_qualifier::type_qualifier_symbol;
use crate::types::decimal::Decimal;
use crate::types::integer::Int;
use crate::{result::IonResult, types::timestamp::Timestamp, IonType, Symbol};
use crate::types::Decimal;
use crate::types::Int;
use crate::{result::IonResult, types::Timestamp, IonType, Symbol};
Comment on lines +13 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move types::Timestamp with the other types imports.

use digest::{FixedOutput, Output, Reset, Update};

pub(crate) trait RepresentationEncoder {
Expand Down
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ mod raw_symbol_token_ref;
pub mod reader;
mod shared_symbol_table;
mod stream_reader;
mod symbol;
mod symbol_ref;
mod symbol_table;
mod system_reader;
Expand All @@ -204,15 +203,15 @@ pub use raw_symbol_token::RawSymbolToken;
#[doc(inline)]
pub use raw_symbol_token_ref::RawSymbolTokenRef;

pub use symbol::Symbol;
pub use symbol_ref::SymbolRef;
pub use symbol_table::SymbolTable;

pub use types::decimal::Decimal;
pub use types::integer::Int;
pub use types::string::Str;
pub use types::timestamp::Timestamp;
pub use types::Decimal;
pub use types::Int;
pub use types::IonType;
pub use types::Str;
pub use types::Symbol;
pub use types::Timestamp;

pub use ion_data::IonData;

Expand Down
2 changes: 1 addition & 1 deletion src/raw_reader.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::element::{Blob, Clob};
use crate::raw_symbol_token::RawSymbolToken;
use crate::stream_reader::IonReader;
use crate::types::string::Str;
use crate::types::IonType;
use crate::types::Str;
use crate::{Decimal, Int, IonResult, Timestamp};
use std::fmt::{Display, Formatter};
use std::io::Read;
Expand Down
10 changes: 5 additions & 5 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ use crate::raw_reader::{RawReader, RawStreamItem};
use crate::raw_symbol_token::RawSymbolToken;
use crate::result::{decoding_error, decoding_error_raw, IonResult};
use crate::stream_reader::IonReader;
use crate::symbol::Symbol;
use crate::symbol_table::SymbolTable;
use crate::types::decimal::Decimal;
use crate::types::integer::Int;
use crate::types::timestamp::Timestamp;
use crate::types::Decimal;
use crate::types::Int;
use crate::types::Symbol;
use crate::types::Timestamp;
Comment on lines +16 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I look through a bunch of these, how much should be be consistent with types::{...} style imports?

use crate::{BlockingRawBinaryReader, BlockingRawTextReader, IonType};
use std::fmt::{Display, Formatter};

use crate::types::string::Str;
use crate::types::Str;
/// Configures and constructs new instances of [Reader].
pub struct ReaderBuilder {}

Expand Down
10 changes: 5 additions & 5 deletions src/stream_reader.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::element::{Blob, Clob};
use crate::result::IonResult;
use crate::types::decimal::Decimal;
use crate::types::integer::Int;
use crate::types::string::Str;
use crate::types::timestamp::Timestamp;
use crate::types::Decimal;
use crate::types::Int;
use crate::types::IonType;
use crate::types::Str;
use crate::types::Timestamp;

/**
* This trait captures the format-agnostic parser functionality needed to navigate within an Ion
Expand Down Expand Up @@ -85,7 +85,7 @@ pub trait IonReader {
/// error is encountered while reading, returns [crate::IonError].
fn read_i64(&mut self) -> IonResult<i64>;

/// Attempts to read the current item as an Ion integer and return it as an [crate::Int]. If the
/// Attempts to read the current item as an Ion integer and return it as an [crate::types::Int]. If the
popematt marked this conversation as resolved.
Show resolved Hide resolved
/// current item is not an integer or an IO error is encountered while reading, returns
/// [crate::IonError].
fn read_int(&mut self) -> IonResult<Int>;
Expand Down
2 changes: 1 addition & 1 deletion src/symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::sync::Arc;

use crate::constants::v1_0;
use crate::symbol::Symbol;
use crate::types::Symbol;
use crate::types::SymbolId;

/// Stores mappings from Symbol IDs to text and vice-versa.
Expand Down
10 changes: 5 additions & 5 deletions src/system_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use crate::element::{Blob, Clob};
use crate::raw_reader::{RawReader, RawStreamItem};
use crate::raw_symbol_token::RawSymbolToken;
use crate::result::{decoding_error, decoding_error_raw, illegal_operation, IonError, IonResult};
use crate::symbol::Symbol;
use crate::system_reader::LstPosition::*;
use crate::types::decimal::Decimal;
use crate::types::integer::Int;
use crate::types::string::Str;
use crate::types::timestamp::Timestamp;
use crate::types::Decimal;
use crate::types::Int;
use crate::types::Str;
use crate::types::Symbol;
use crate::types::Timestamp;
use crate::{BlockingRawBinaryReader, IonReader, IonType, SymbolTable};

/// Tracks where the [SystemReader] is in the process of reading a local symbol table.
Expand Down