Skip to content

Commit

Permalink
Clean up imports, newlines, and doc code (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
popematt authored May 1, 2023
1 parent b8e8e82 commit fd09e87
Show file tree
Hide file tree
Showing 43 changed files with 161 additions and 227 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Unix-style newlines with a newline ending every file. `rustfmt` already
# enforces these rules for Rust files, but this informs IDEs to do the same
# for all files.
[*]
end_of_line = lf
insert_final_newline = true
9 changes: 9 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
newline_style = "Unix"

# These properties intentionally commented out. You can uncomment them and
# run `cargo +nightly fmt` locally, but they should not be enforced in CI
# workflow until they are stable.

# format_code_in_doc_comments = true
# imports_granularity = 'Module'
# imports_layout = "HorizontalVertical"
3 changes: 1 addition & 2 deletions examples/read_all_values.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use ion_rs::binary::non_blocking::raw_binary_reader::RawBinaryReader;
use ion_rs::raw_reader::RawStreamItem;
use ion_rs::result::IonResult;
use ion_rs::RawReader;
use ion_rs::{BlockingRawBinaryReader, IonType};
use ion_rs::{BlockingRawBinaryReader, IonType, RawReader};
use memmap::MmapOptions;
use std::fs::File;
use std::process::exit;
Expand Down
6 changes: 2 additions & 4 deletions src/binary/binary_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ 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;
use crate::types::SymbolId;
use crate::types::Timestamp;
use crate::types::{Decimal, Int, IonType, SymbolId, Timestamp};
use crate::writer::IonWriter;
use crate::{types::Int, types::IonType, SymbolTable};
use crate::SymbolTable;
use delegate::delegate;
use std::io::Write;

Expand Down
15 changes: 7 additions & 8 deletions src/binary/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ use std::io::Write;
use arrayvec::ArrayVec;
use bigdecimal::Zero;

use crate::binary::int::DecodedInt;
use crate::binary::raw_binary_writer::MAX_INLINE_LENGTH;
use crate::binary::var_int::VarInt;
use crate::binary::var_uint::VarUInt;
use crate::ion_data::IonEq;
use crate::{
binary::{
int::DecodedInt, raw_binary_writer::MAX_INLINE_LENGTH, var_int::VarInt, var_uint::VarUInt,
},
result::IonResult,
types::{Coefficient, Decimal, Sign, UInt},
IonError,
};
use crate::result::IonResult;
use crate::types::{Coefficient, Decimal, Sign, UInt};
use crate::IonError;

const DECIMAL_BUFFER_SIZE: usize = 32;
const DECIMAL_POSITIVE_ZERO: Decimal = Decimal {
Expand Down
10 changes: 5 additions & 5 deletions src/binary/header.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::convert::TryFrom;

use crate::{
binary::{constants::v1_0::length_codes, nibbles::nibbles_from_byte, IonTypeCode},
result::IonResult,
types::IonType,
};
use crate::binary::constants::v1_0::length_codes;
use crate::binary::nibbles::nibbles_from_byte;
use crate::binary::IonTypeCode;
use crate::result::IonResult;
use crate::types::IonType;

/// Contains all of the information that can be extracted from the one-octet type descriptor
/// found at the beginning of each value in a binary Ion stream.
Expand Down
3 changes: 1 addition & 2 deletions src/binary/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use std::mem;
use crate::data_source::IonDataSource;
use crate::result::{decoding_error, IonResult};
use crate::types;
use crate::types::Coefficient;
use crate::types::Int;
use crate::types::{Coefficient, Int};
use num_bigint::{BigInt, Sign};
use num_traits::Zero;
use std::io::Write;
Expand Down
13 changes: 4 additions & 9 deletions src/binary/non_blocking/raw_binary_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ 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::raw_reader::BufferedRawReader;
use crate::result::{
decoding_error, decoding_error_raw, illegal_operation, illegal_operation_raw,
incomplete_data_error,
};
use crate::types::IntAccess;
use crate::types::Str;
use crate::types::SymbolId;
use crate::types::{Blob, Clob};
use crate::{
raw_reader::BufferedRawReader, types::Decimal, Int, IonReader, IonResult, IonType,
RawStreamItem, RawSymbolToken, Timestamp,
};
use crate::types::{Blob, Clob, Decimal, IntAccess, Str, SymbolId};
use crate::{Int, IonReader, IonResult, IonType, RawStreamItem, RawSymbolToken, Timestamp};
use bytes::{BigEndian, Buf, ByteOrder};
use num_bigint::BigUint;
use num_traits::Zero;
Expand Down Expand Up @@ -2047,7 +2042,7 @@ mod tests {
assert_eq!(cursor.raw_header_bytes(), Some(&ion_data[15..=15]));
assert_eq!(
cursor.raw_value_bytes(),
Some(&ion_data[15..15] /*That is, zero bytes*/)
Some(&ion_data[15..15] /* That is, zero bytes */)
);
Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions src/binary/non_blocking/type_descriptor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
binary::{constants::v1_0::length_codes, nibbles::nibbles_from_byte, IonTypeCode},
types::IonType,
};
use crate::binary::constants::v1_0::length_codes;
use crate::binary::nibbles::nibbles_from_byte;
use crate::binary::IonTypeCode;
use crate::types::IonType;

/// Contains all of the information that can be extracted from the one-octet type descriptor
/// found at the beginning of each value, annotations wrapper, IVM, or NOP in a binary Ion stream.
Expand Down
7 changes: 2 additions & 5 deletions src/binary/raw_binary_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ 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;
use crate::types::Timestamp;
use crate::types::{ContainerType, SymbolId};
use crate::types::{ContainerType, Decimal, SymbolId, Timestamp};
use crate::writer::IonWriter;
use crate::{Int, IonType};

Expand Down Expand Up @@ -912,8 +910,7 @@ mod writer_tests {
use super::*;
use crate::raw_symbol_token::{local_sid_token, RawSymbolToken};
use crate::reader::{Reader, ReaderBuilder};
use crate::types::Symbol;
use crate::types::{Blob, Clob};
use crate::types::{Blob, Clob, Symbol};
use crate::IonReader;
use num_bigint::BigInt;
use num_traits::Float;
Expand Down
22 changes: 9 additions & 13 deletions src/binary/timestamp.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// Copyright Amazon.com, Inc. or its affiliates.

use std::{io::Write, ops::Neg};
use std::io::Write;
use std::ops::Neg;

use arrayvec::ArrayVec;
use chrono::{Datelike, Timelike};

use crate::{
binary::{
decimal::DecimalBinaryEncoder, raw_binary_writer::MAX_INLINE_LENGTH, var_int::VarInt,
var_uint::VarUInt,
},
result::IonResult,
types::{Decimal, Mantissa, Precision, Timestamp},
};
use crate::binary::decimal::DecimalBinaryEncoder;
use crate::binary::raw_binary_writer::MAX_INLINE_LENGTH;
use crate::binary::var_int::VarInt;
use crate::binary::var_uint::VarUInt;
use crate::result::IonResult;
use crate::types::{Decimal, Mantissa, Precision, Timestamp};

const MAX_TIMESTAMP_LENGTH: usize = 32;

Expand Down Expand Up @@ -131,10 +130,7 @@ where
#[cfg(test)]
mod binary_timestamp_tests {
use super::*;
use crate::reader;
use crate::IonReader;
use crate::IonType;
use crate::ReaderBuilder;
use crate::{reader, IonReader, IonType, ReaderBuilder};
use rstest::*;

// These tests show how varying levels of precision affects number of bytes
Expand Down
2 changes: 1 addition & 1 deletion src/blocking_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ mod tests {
assert_eq!(cursor.raw_header_bytes(), Some(&ion_data[15..=15]));
assert_eq!(
cursor.raw_value_bytes(),
Some(&ion_data[15..15] /*That is, zero bytes*/)
Some(&ion_data[15..15] /* That is, zero bytes */)
);
Ok(())
}
Expand Down
3 changes: 1 addition & 2 deletions src/catalog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::result::IonResult;
use crate::result::{illegal_operation, illegal_operation_raw};
use crate::result::{illegal_operation, illegal_operation_raw, IonResult};
use crate::shared_symbol_table::SharedSymbolTable;
use std::collections::{BTreeMap, HashMap};

Expand Down
73 changes: 33 additions & 40 deletions src/element/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ use crate::Symbol;
/// Building a [Sequence]:
/// ```
/// use ion_rs::element::{Element, Sequence};
/// let actual: Sequence = Sequence::builder()
/// .push(1)
/// .push(true)
/// .push("foo")
/// .build();
/// let actual: Sequence = Sequence::builder().push(1).push(true).push("foo").build();
/// let expected: Sequence = Sequence::new([
/// Element::integer(1),
/// Element::boolean(true),
/// Element::string("foo"),
/// Element::integer(1),
/// Element::boolean(true),
/// Element::string("foo"),
/// ]);
/// assert_eq!(actual, expected);
/// ```
Expand All @@ -27,9 +23,9 @@ use crate::Symbol;
/// .push("foo")
/// .build_list();
/// let expected: List = List(Sequence::new([
/// Element::integer(1),
/// Element::boolean(true),
/// Element::string("foo"),
/// Element::integer(1),
/// Element::boolean(true),
/// Element::string("foo"),
/// ]));
/// assert_eq!(actual, expected);
/// ```
Expand All @@ -42,9 +38,9 @@ use crate::Symbol;
/// .push("foo")
/// .build_sexp();
/// let expected: SExp = SExp(Sequence::new([
/// Element::integer(1),
/// Element::boolean(true),
/// Element::string("foo"),
/// Element::integer(1),
/// Element::boolean(true),
/// Element::string("foo"),
/// ]));
/// assert_eq!(actual, expected);
/// ```
Expand Down Expand Up @@ -101,27 +97,29 @@ impl SequenceBuilder {
/// Constructs [Struct] values incrementally.
///
/// ```
/// use ion_rs::ion_struct;
/// use ion_rs::element::Element;
/// use ion_rs::ion_struct;
/// let actual: Element = ion_struct! {
/// "a": 1,
/// "b": true,
/// "c": "foo"
/// }.into();
/// }
/// .into();
/// let expected = Element::read_one(r#"{a: 1, b: true, c: "foo"}"#).unwrap();
/// assert_eq!(actual, expected);
/// ```
///
/// ```
/// use ion_rs::element::{Element, Struct};
/// use ion_rs::ion_struct;
/// use ion_rs::element::{Struct, Element};
/// let base_struct: Struct = ion_struct! {
/// "foo": 1,
/// "bar": 2,
/// "baz": 3
/// };
///
/// let modified_struct: Element = base_struct.clone_builder()
/// let modified_struct: Element = base_struct
/// .clone_builder()
/// .remove_field("bar")
/// .with_field("quux", 4)
/// .build()
Expand Down Expand Up @@ -162,8 +160,8 @@ impl StructBuilder {
/// Adds all of the provided `(name, value)` pairs to the [`Struct`] being constructed.
///
/// ```
/// use ion_rs::ion_struct;
/// use ion_rs::element::{Element, Struct};
/// use ion_rs::ion_struct;
///
/// let struct1 = ion_struct! {
/// "foo": 1,
Expand All @@ -184,7 +182,6 @@ impl StructBuilder {
///
/// let expected = Element::read_one("{foo: 1, bar: 2, baz: 3, a: 4, b: 5, c: 6}").unwrap();
/// ```
///
pub fn with_fields<S, E, I>(mut self, fields: I) -> Self
where
S: Into<Symbol>,
Expand Down Expand Up @@ -222,15 +219,10 @@ impl StructBuilder {
/// Constructs a list [`Element`] with the specified child values.
///
/// ```
/// use ion_rs::ion_list;
/// use ion_rs::element::Element;
/// use ion_rs::ion_list;
/// // Construct a list Element from Rust values
/// let actual: Element = ion_list![
/// "foo",
/// 7,
/// false,
/// ion_list![1.5f64, -8.25f64]
/// ].into();
/// let actual: Element = ion_list!["foo", 7, false, ion_list![1.5f64, -8.25f64]].into();
/// // Construct an Element from serialized Ion data
/// let expected = Element::read_one(r#"["foo", 7, false, [1.5e0, -8.25e0]]"#).unwrap();
/// // Compare the two Elements
Expand All @@ -242,8 +234,8 @@ impl StructBuilder {
///
/// ```
/// // Construct a list Element from existing Elements
/// use ion_rs::ion_list;
/// use ion_rs::element::{Element, IntoAnnotatedElement};
/// use ion_rs::ion_list;
///
/// let string_element: Element = "foo".into();
/// let bool_element: Element = true.into();
Expand All @@ -254,7 +246,8 @@ impl StructBuilder {
/// 10i64.with_annotations(["bar"]), // .with_annotations() constructs an Element
/// Element::clob("hello"),
/// Element::symbol("world")
/// ].into();
/// ]
/// .into();
/// // Construct an Element from serialized Ion data
/// let expected = Element::read_one(r#"["foo", true, bar::10, {{"hello"}}, world]"#).unwrap();
/// // Compare the two Elements
Expand Down Expand Up @@ -318,13 +311,13 @@ macro_rules! ion_sexp {
/// `Into<Element>`.
///
/// ```
/// use ion_rs::{ion_struct, IonType};
/// use ion_rs::element::Element;
/// use ion_rs::{ion_struct, IonType};
/// let field_name_2 = "x";
/// let prefix = "abc";
/// let suffix = "def";
/// // Construct an s-expression Element from Rust values
/// let actual = ion_struct!{
/// let actual = ion_struct! {
/// "w": "foo",
/// // ^--- Quoted strings are field name literals
/// // v--- Unquoted field names are interpreted as variables
Expand All @@ -334,9 +327,13 @@ macro_rules! ion_sexp {
/// // Arbitrary expressions are acceptable, though some may require
/// // v--- an extra scope (braces: `{}`) to be understood properly.
/// {format!("{}_{}", prefix, suffix)}: IonType::Null
/// }.into();
/// }
/// .into();
/// // Construct an Element from serialized Ion data
/// let expected = Element::read_one(r#"{w: "foo", x: 7, y: false, z: {a: 1.5e0, b: -8.25e0}, abc_def: null}"#).unwrap();
/// let expected = Element::read_one(
/// r#"{w: "foo", x: 7, y: false, z: {a: 1.5e0, b: -8.25e0}, abc_def: null}"#,
/// )
/// .unwrap();
/// // Compare the two Elements
/// assert_eq!(expected, actual);
/// ```
Expand All @@ -348,18 +345,14 @@ macro_rules! ion_struct {
}};
}

use crate::types::List;
use crate::types::SExp;
pub use ion_list;
pub use ion_sexp;
pub use ion_struct;
use crate::types::{List, SExp};
pub use {ion_list, ion_sexp, ion_struct};

#[cfg(test)]
mod tests {
use crate::element::builders::{SequenceBuilder, StructBuilder};
use crate::element::Element;
use crate::Symbol;
use crate::{ion_list, ion_sexp, ion_struct};
use crate::{ion_list, ion_sexp, ion_struct, Symbol};

#[test]
fn make_list_with_builder() {
Expand Down
Loading

0 comments on commit fd09e87

Please sign in to comment.