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

Mass renaming, container Display impls #486

Merged
merged 16 commits into from
Mar 16, 2023
2 changes: 1 addition & 1 deletion examples/read_all_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn read_all_values<R: RawReader>(reader: &mut R) -> IonResult<usize> {
Timestamp => {
let _timestamp = reader.read_timestamp()?;
}
Boolean => {
Bool => {
let _boolean = reader.read_bool()?;
}
Blob => {
Expand Down
2 changes: 1 addition & 1 deletion src/binary/non_blocking/binary_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl<A: AsRef<[u8]>> BinaryBuffer<A> {
let length_code = match header.ion_type {
// Null (0x0F) and Boolean (0x10, 0x11) are the only types that don't have/use a `length`
// field; the header contains the complete value.
Null | Boolean => 0,
Null | Bool => 0,
// If a struct has length = 1, its fields are ordered and the actual length follows.
// For the time being, this reader does not have any special handling for this case.
// Use `0xE` (14) as the length code instead so the call to `read_length` below
Expand Down
4 changes: 2 additions & 2 deletions src/binary/non_blocking/raw_binary_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ impl<A: AsRef<[u8]>> IonReader for RawBinaryBufferReader<A> {
}

fn read_bool(&mut self) -> IonResult<bool> {
let (encoded_value, _) = self.value_and_bytes(IonType::Boolean)?;
let (encoded_value, _) = self.value_and_bytes(IonType::Bool)?;

let representation = encoded_value.header.length_code;
match representation {
Expand Down Expand Up @@ -1763,7 +1763,7 @@ mod tests {
reader.step_in()?;
expect_value(reader.next(), IonType::Struct);
reader.step_in()?;
expect_value(reader.next(), IonType::Boolean);
expect_value(reader.next(), IonType::Bool);
assert_eq!(reader.field_name()?, RawSymbolToken::SymbolId(4));
let item = reader.next()?;
assert_eq!(item, RawStreamItem::Nothing);
Expand Down
2 changes: 1 addition & 1 deletion src/binary/non_blocking/type_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl TypeDescriptor {
let ion_type = match ion_type_code {
NullOrNop if length_code == length_codes::NULL => Some(IonType::Null),
NullOrNop => None,
Boolean => Some(IonType::Boolean),
Boolean => Some(IonType::Bool),
PositiveInteger => Some(IonType::Integer),
NegativeInteger => Some(IonType::Integer),
Float => Some(IonType::Float),
Expand Down
14 changes: 7 additions & 7 deletions src/binary/raw_binary_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ impl<R: IonDataSource> IonReader for RawBinaryReader<R> {
}

fn read_bool(&mut self) -> IonResult<bool> {
read_safety_checks!(self, IonType::Boolean);
read_safety_checks!(self, IonType::Bool);

// No reading from the stream occurs -- the header contains all of the information we need.
let representation = self.cursor.value.header.length_code;
Expand Down Expand Up @@ -1258,15 +1258,15 @@ mod tests {
#[test]
fn test_read_bool_false() -> IonResult<()> {
let mut cursor = ion_cursor_for(&[0x10]);
assert_eq!(cursor.next()?, Value(IonType::Boolean));
assert_eq!(cursor.next()?, Value(IonType::Bool));
assert!(!(cursor.read_bool()?));
Ok(())
}

#[test]
fn test_read_bool_true() -> IonResult<()> {
let mut cursor = ion_cursor_for(&[0x11]);
assert_eq!(cursor.next()?, Value(IonType::Boolean));
assert_eq!(cursor.next()?, Value(IonType::Bool));
assert!(cursor.read_bool()?);
Ok(())
}
Expand Down Expand Up @@ -1678,7 +1678,7 @@ mod tests {
cursor.step_out()?; // Step out of struct

// Second top-level value
assert_eq!(RawStreamItem::Value(IonType::Boolean), cursor.next()?);
assert_eq!(RawStreamItem::Value(IonType::Bool), cursor.next()?);
assert_eq!(cursor.raw_bytes(), Some(&ion_data[12..16]));
assert_eq!(cursor.raw_field_id_bytes(), None);
assert_eq!(cursor.raw_annotations_bytes(), Some(&ion_data[12..=14]));
Expand Down Expand Up @@ -1758,7 +1758,7 @@ mod tests {
cursor.step_out()?;

// false
assert_eq!(RawStreamItem::Value(IonType::Boolean), cursor.next()?);
assert_eq!(RawStreamItem::Value(IonType::Bool), cursor.next()?);
assert_eq!(cursor.raw_bytes(), Some(&ion_data[37..=37]));
assert_eq!(cursor.raw_field_id_bytes(), None);
assert_eq!(cursor.raw_annotations_bytes(), None);
Expand All @@ -1784,7 +1784,7 @@ mod tests {
0x00, // NOP code, 1 byte NOP. Also NOP at EOF :)
]);

assert_eq!(cursor.next()?, Value(IonType::Boolean));
assert_eq!(cursor.next()?, Value(IonType::Bool));
assert_eq!(cursor.next()?, Nothing);

Ok(())
Expand All @@ -1800,7 +1800,7 @@ mod tests {
0x11, // boolean true
]);

assert_eq!(cursor.next()?, Value(IonType::Boolean));
assert_eq!(cursor.next()?, Value(IonType::Bool));
assert_eq!(cursor.next()?, Nothing);

Ok(())
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 @@ -547,7 +547,7 @@ impl<W: Write> IonWriter for RawBinaryWriter<W> {
self.write_scalar(|enc_buffer| {
let byte: u8 = match ion_type {
IonType::Null => 0x0F,
IonType::Boolean => 0x1F,
IonType::Bool => 0x1F,
IonType::Integer => 0x2F,
IonType::Float => 0x4F,
IonType::Decimal => 0x5F,
Expand Down Expand Up @@ -970,7 +970,7 @@ mod writer_tests {
fn binary_writer_nulls() -> IonResult<()> {
let ion_types = &[
IonType::Null,
IonType::Boolean,
IonType::Bool,
IonType::Integer,
IonType::Float,
IonType::Decimal,
Expand Down Expand Up @@ -1004,7 +1004,7 @@ mod writer_tests {
fn binary_writer_bools() -> IonResult<()> {
binary_writer_scalar_test(
&[true, false],
IonType::Boolean,
IonType::Bool,
|writer, v| writer.write_bool(*v),
|reader| reader.read_bool(),
)
Expand Down Expand Up @@ -1132,7 +1132,7 @@ mod writer_tests {
}

fn expect_bool(reader: &mut TestReader, value: bool) {
expect_scalar(reader, IonType::Boolean, |r| r.read_bool(), value);
expect_scalar(reader, IonType::Bool, |r| r.read_bool(), value);
}

fn expect_integer(reader: &mut TestReader, value: i64) {
Expand Down
2 changes: 1 addition & 1 deletion src/binary/type_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl TryFrom<IonTypeCode> for IonType {
use IonTypeCode::*;
let ion_type = match ion_type_code {
NullOrNop => IonType::Null,
Boolean => IonType::Boolean,
Boolean => IonType::Bool,
PositiveInteger | NegativeInteger => IonType::Integer,
Float => IonType::Float,
Decimal => IonType::Decimal,
Expand Down
6 changes: 3 additions & 3 deletions src/element/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl From<StructBuilder> for Element {
#[macro_export]
macro_rules! ion_list {
($($element:expr),*) => {{
use $crate::value::owned::List;
use $crate::element::owned::List;
List::builder()$(.push($element))*.build()
}};
}
Expand Down Expand Up @@ -340,7 +340,7 @@ macro_rules! ion_list {
#[macro_export]
macro_rules! ion_sexp {
($($element:expr)*) => {{
use $crate::value::owned::SExp;
use $crate::element::owned::SExp;
SExp::builder()$(.push($element))*.build()
}};
}
Expand Down Expand Up @@ -376,7 +376,7 @@ macro_rules! ion_sexp {
#[macro_export]
macro_rules! ion_struct {
($($field_name:tt : $element:expr),*) => {{
use $crate::value::owned::Struct;
use $crate::element::owned::Struct;
Struct::builder()$(.with_field($field_name, $element))*.build()
}};
}
Expand Down
4 changes: 2 additions & 2 deletions src/element/element_stream_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ mod reader_tests {
next_type(reader, IonType::Integer, false);
next_type(reader, IonType::SExp, false);
reader.step_in()?;
next_type(reader, IonType::Boolean, false);
next_type(reader, IonType::Boolean, false);
next_type(reader, IonType::Bool, false);
next_type(reader, IonType::Bool, false);
// The reader is now at the second 'true' in the s-expression nested in 'bar'/'b'
reader.step_out()?;
reader.step_out()?;
Expand Down
2 changes: 1 addition & 1 deletion src/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ mod tests {
fn bool_case() -> Case {
Case {
elem: true.into(),
ion_type: IonType::Boolean,
ion_type: IonType::Bool,
ops: vec![AsBool],
op_assert: Box::new(|e: &Element| {
let expected = Element::from(true);
Expand Down
2 changes: 1 addition & 1 deletion src/element/native_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<W: IonWriter> NativeElementWriter<W> {

match element.ion_type() {
IonType::Null => unreachable!("element has IonType::Null but is_null() was false"),
IonType::Boolean => self.writer.write_bool(element.as_boolean().unwrap()),
IonType::Bool => self.writer.write_bool(element.as_boolean().unwrap()),
IonType::Integer => self.writer.write_integer(element.as_integer().unwrap()),
IonType::Float => self.writer.write_f64(element.as_float().unwrap()),
IonType::Decimal => self.writer.write_decimal(element.as_decimal().unwrap()),
Expand Down
10 changes: 5 additions & 5 deletions src/element/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ pub enum Value {
Timestamp(Timestamp),
String(String),
Symbol(Symbol),
Boolean(bool),
Bool(bool),
Blob(Vec<u8>),
Clob(Vec<u8>),
SExp(SExp),
Expand Down Expand Up @@ -440,7 +440,7 @@ impl Display for Element {

match &self.value {
Value::Null(ion_type) => ivf.format_null(*ion_type),
Value::Boolean(bool) => ivf.format_bool(*bool),
Value::Bool(bool) => ivf.format_bool(*bool),
Value::Integer(integer) => ivf.format_integer(integer),
Value::Float(float) => ivf.format_float(*float),
Value::Decimal(decimal) => ivf.format_decimal(decimal),
Expand Down Expand Up @@ -530,7 +530,7 @@ impl From<Timestamp> for Value {

impl From<bool> for Value {
fn from(bool_val: bool) -> Self {
Value::Boolean(bool_val)
Value::Bool(bool_val)
}
}

Expand Down Expand Up @@ -612,7 +612,7 @@ impl Element {
Timestamp(_) => IonType::Timestamp,
String(_) => IonType::String,
Symbol(_) => IonType::Symbol,
Boolean(_) => IonType::Boolean,
Bool(_) => IonType::Bool,
Blob(_) => IonType::Blob,
Clob(_) => IonType::Clob,
SExp(_) => IonType::SExp,
Expand Down Expand Up @@ -695,7 +695,7 @@ impl Element {

pub fn as_boolean(&self) -> Option<bool> {
match &self.value {
Value::Boolean(b) => Some(*b),
Value::Bool(b) => Some(*b),
_ => None,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/element/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<'a, R: IonReader<Item = StreamItem, Symbol = Symbol>> ElementLoader<'a, R>
use crate::IonType::*;
match ion_type {
Null => unreachable!("non-null value had IonType::Null"),
Boolean => Value::Boolean(self.reader.read_bool()?),
Bool => Value::Bool(self.reader.read_bool()?),
Integer => Value::Integer(self.reader.read_integer()?),
Float => Value::Float(self.reader.read_f64()?),
Decimal => Value::Decimal(self.reader.read_decimal()?),
Expand Down Expand Up @@ -225,7 +225,7 @@ mod reader_tests {
"#,
vec![
Null(IonType::Null),
Null(IonType::Boolean),
Null(IonType::Bool),
Null(IonType::Integer),
Null(IonType::Float),
Null(IonType::Decimal),
Expand All @@ -235,7 +235,7 @@ mod reader_tests {
Null(IonType::Clob),
Null(IonType::Blob),
Null(IonType::List),
Null(IonType::SExpression),
Null(IonType::SExp),
Copy link
Contributor

Choose a reason for hiding this comment

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

What are you doing here? You belong in the previous commit!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😅 Yeah, there were a few of these. I really need to set up a pre-commit git hook for cargo test --all-features to prevent this sort of thing.

Null(IonType::Struct),
].into_iter().map(|v| v.into()).collect(),
)]
Expand Down
2 changes: 1 addition & 1 deletion src/ion_hash/representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use digest::{FixedOutput, Output, Reset, Update};
pub(crate) trait RepresentationEncoder {
fn update_with_representation(&mut self, elem: &Element) -> IonResult<()> {
match elem.ion_type() {
IonType::Null | IonType::Boolean => {} // these types have no representation
IonType::Null | IonType::Bool => {} // these types have no representation
IonType::Integer => self.write_repr_integer(elem.as_integer())?,
IonType::Float => self.write_repr_float(elem.as_float())?,
IonType::Decimal => self.write_repr_decimal(elem.as_decimal())?,
Expand Down
2 changes: 1 addition & 1 deletion src/ion_hash/type_qualifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl TypeQualifier {
pub(crate) fn from_element(elem: &Element) -> TypeQualifier {
match elem.ion_type() {
IonType::Null => type_qualifier_null(),
IonType::Boolean => type_qualifier_boolean(elem.as_boolean()),
IonType::Bool => type_qualifier_boolean(elem.as_boolean()),
IonType::Integer => type_qualifier_integer(elem.as_integer()),
IonType::Float => type_qualifier_float(elem.as_float()),
IonType::Decimal => type_qualifier_decimal(elem.as_decimal()),
Expand Down
8 changes: 4 additions & 4 deletions src/text/non_blocking/raw_text_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,8 +1117,8 @@ mod reader_tests {
next_type(reader, IonType::Integer, false);
next_type(reader, IonType::SExp, false);
reader.step_in()?;
next_type(reader, IonType::Boolean, false);
next_type(reader, IonType::Boolean, false);
next_type(reader, IonType::Bool, false);
next_type(reader, IonType::Bool, false);
// The reader is now at the second 'true' in the s-expression nested in 'bar'/'b'
reader.step_out()?;
reader.step_out()?;
Expand Down Expand Up @@ -1208,7 +1208,7 @@ mod reader_tests {
reader.stream_complete();
next_type(reader, IonType::Null, true);

next_type(reader, IonType::Boolean, false);
next_type(reader, IonType::Bool, false);
assert!(reader.read_bool()?);

next_type(reader, IonType::Integer, false);
Expand Down Expand Up @@ -1328,7 +1328,7 @@ mod reader_tests {
next_type(reader, IonType::Null, true);
annotations_eq(reader, ["mercury"]);

next_type(reader, IonType::Boolean, false);
next_type(reader, IonType::Bool, false);
assert!(reader.read_bool()?);
annotations_eq(reader, ["venus", "earth"]);

Expand Down
2 changes: 1 addition & 1 deletion src/text/parent_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod parent_container_tests {

#[rstest]
#[case::list(IonType::List)]
#[case::list(IonType::SExpression)]
#[case::list(IonType::SExp)]
#[case::list(IonType::Struct)]
#[should_panic]
#[case::list(IonType::Integer)]
Expand Down
4 changes: 2 additions & 2 deletions src/text/parsers/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn ion_type_from_text(text: &str) -> Option<IonType> {
use IonType::*;
let ion_type = match text {
"null" => Null,
"bool" => Boolean,
"bool" => Bool,
"int" => Integer,
"float" => Float,
"decimal" => Decimal,
Expand Down Expand Up @@ -70,7 +70,7 @@ mod null_parsing_tests {
use IonType::*;
parse_equals("null ", Null);
parse_equals("null.null ", Null);
parse_equals("null.bool ", Boolean);
parse_equals("null.bool ", Bool);
parse_equals("null.int ", Integer);
parse_equals("null.float ", Float);
parse_equals("null.decimal ", Decimal);
Expand Down
4 changes: 2 additions & 2 deletions src/text/parsers/top_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ mod parse_top_level_values_tests {
expect_type("null ", IonType::Null);
expect_type("null.timestamp ", IonType::Timestamp);
expect_type("null.list ", IonType::List);
expect_type("true ", IonType::Boolean);
expect_type("false ", IonType::Boolean);
expect_type("true ", IonType::Bool);
expect_type("false ", IonType::Bool);
expect_type("5 ", IonType::Integer);
expect_type("-5 ", IonType::Integer);
expect_type("5.0 ", IonType::Decimal);
Expand Down
8 changes: 4 additions & 4 deletions src/text/raw_text_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ mod reader_tests {
next_type(reader, IonType::Integer, false);
next_type(reader, IonType::SExp, false);
reader.step_in()?;
next_type(reader, IonType::Boolean, false);
next_type(reader, IonType::Boolean, false);
next_type(reader, IonType::Bool, false);
next_type(reader, IonType::Bool, false);
// The reader is now at the second 'true' in the s-expression nested in 'bar'/'b'
reader.step_out()?;
reader.step_out()?;
Expand Down Expand Up @@ -369,7 +369,7 @@ mod reader_tests {
let reader = &mut RawTextReader::new(ion_data)?;
next_type(reader, IonType::Null, true);

next_type(reader, IonType::Boolean, false);
next_type(reader, IonType::Bool, false);
assert!(reader.read_bool()?);

next_type(reader, IonType::Integer, false);
Expand Down Expand Up @@ -488,7 +488,7 @@ mod reader_tests {
next_type(reader, IonType::Null, true);
annotations_eq(reader, ["mercury"]);

next_type(reader, IonType::Boolean, false);
next_type(reader, IonType::Bool, false);
assert!(reader.read_bool()?);
annotations_eq(reader, ["venus", "earth"]);

Expand Down
Loading