Skip to content

Commit 80829c2

Browse files
committed
cargo fmt
1 parent a2504e8 commit 80829c2

File tree

8 files changed

+40
-33
lines changed

8 files changed

+40
-33
lines changed

benches/my_benchmark.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2-
use ion_binary_rs::{IonParser, IonEncoder};
2+
use ion_binary_rs::{IonEncoder, IonParser};
33

44
fn criterion_benchmark(c: &mut Criterion) {
55
c.bench_function("ion decode simple", |b| {
@@ -41,7 +41,9 @@ fn criterion_benchmark(c: &mut Criterion) {
4141
};
4242

4343
b.iter(|| {
44-
bson::raw::RawDocumentBuf::from_document(&doc.clone()).unwrap().into_bytes()
44+
bson::raw::RawDocumentBuf::from_document(&doc.clone())
45+
.unwrap()
46+
.into_bytes()
4547
})
4648
});
4749
}

src/binary_encoder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ pub fn encode_varint(value: &[u8], is_negative: bool) -> Vec<u8> {
428428
}
429429

430430
pub fn encode_var(input: &[u8]) -> Vec<u8> {
431-
432431
if input.is_empty() {
433432
return vec![];
434433
}
@@ -537,7 +536,7 @@ pub fn encode_var(input: &[u8]) -> Vec<u8> {
537536
}
538537
}
539538

540-
// Output len was all iterated as the loop breaks on
539+
// Output len was all iterated as the loop breaks on
541540
// output_index == 0 and it started as output_len - 1
542541
unsafe {
543542
buffer_output.set_len(output_len);

src/binary_parser_types.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ pub enum ValueType {
6666
}
6767

6868
impl TryFrom<u8> for ValueType {
69-
7069
type Error = ParsingError;
7170

7271
fn try_from(id: u8) -> Result<Self, ParsingError> {
@@ -125,8 +124,12 @@ pub enum ParsingError {
125124
impl PartialEq for ParsingError {
126125
fn eq(&self, input: &ParsingError) -> bool {
127126
match (self, input) {
128-
(ParsingError::ErrorReadingData(a), ParsingError::ErrorReadingData(b)) if a.kind() == b.kind() => true,
129-
(a, b) => a == b
127+
(ParsingError::ErrorReadingData(a), ParsingError::ErrorReadingData(b))
128+
if a.kind() == b.kind() =>
129+
{
130+
true
131+
}
132+
(a, b) => a == b,
130133
}
131134
}
132135
}
@@ -152,7 +155,7 @@ impl ValueHeader {
152155

153156
pub fn is_nop(&self) -> bool {
154157
let ion_type = self.get_type();
155-
158+
156159
ion_type == ValueType::Null && self.get_len() < 15
157160
}
158161

@@ -194,7 +197,7 @@ impl ValueHeader {
194197
13 => ValueType::Struct,
195198
14 => ValueType::Annotation,
196199
15 => ValueType::Reserved,
197-
_ => panic!("Internal library bug")
200+
_ => panic!("Internal library bug"),
198201
}
199202
}
200203
}

src/ion_parser.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,15 @@ impl<T: Read> IonParser<T> {
9898
}
9999

100100
#[inline]
101-
fn consume_value_body(&mut self, value_header: &ValueHeader, nested_level: u64) -> ConsumerResult {
101+
fn consume_value_body(
102+
&mut self,
103+
value_header: &ValueHeader,
104+
nested_level: u64,
105+
) -> ConsumerResult {
102106
if value_header.is_nop() {
103107
let consumed_bytes = self.consume_nop(value_header)?;
104108
let value = self.consume_value()?;
105-
return Ok((value.0, value.1 + consumed_bytes))
109+
return Ok((value.0, value.1 + consumed_bytes));
106110
}
107111

108112
match value_header.get_type() {
@@ -178,7 +182,7 @@ impl<T: Read> IonParser<T> {
178182
}
179183

180184
let (length, _, total) = self.consume_value_len(header)?;
181-
// Not using the temp buffer because from_utf8 consumes the
185+
// Not using the temp buffer because from_utf8 consumes the
182186
// arguments and it would require a clone of a buffer that
183187
// might be bigger than required.
184188
let mut buffer = vec![0; length];
@@ -272,11 +276,13 @@ impl<T: Read> IonParser<T> {
272276

273277
trace!("Struct key field: {:?}", key);
274278

275-
let value_header = self.parser.consume_value_header(nested_level.saturating_add(1))?;
279+
let value_header = self
280+
.parser
281+
.consume_value_header(nested_level.saturating_add(1))?;
276282

277283
consumed_bytes += 1;
278284

279-
if value_header.is_nop() {
285+
if value_header.is_nop() {
280286
let consumed = self.consume_nop(&value_header)?;
281287
trace!("Found NOP Padding in Struct of {:} bytes", consumed + 1);
282288
consumed_bytes += consumed;
@@ -314,7 +320,9 @@ impl<T: Read> IonParser<T> {
314320
let mut values = vec![];
315321

316322
while length - consumed_bytes > 0 {
317-
let value_header = self.parser.consume_value_header(nested_level.saturating_add(1))?;
323+
let value_header = self
324+
.parser
325+
.consume_value_header(nested_level.saturating_add(1))?;
318326

319327
consumed_bytes += 1;
320328

@@ -743,7 +751,6 @@ impl<T: Read> IonParser<T> {
743751
header.get_len().into()
744752
};
745753

746-
747754
let total = consumed_bytes + length;
748755

749756
Ok((length, consumed_bytes, total))

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
//!
1010
//! It **parses**, **encodes** and **hashes** anything you throw at it. Any failure to do so
1111
//! is a bug that we will fix and we will be very happy if you report them.
12-
//!
12+
//!
1313
//! The code is mature and way more tested than Amazon's alternatives, including their js
1414
//! library. Amazon, when implementing the "good tests" only check that it parses. We check
15-
//! that the value is the correct one too. Additionally, we seem to be implementing way
16-
//! more of the ion protocol than Amazon's libraries, as we don't have huge skip lists in
15+
//! that the value is the correct one too. Additionally, we seem to be implementing way
16+
//! more of the ion protocol than Amazon's libraries, as we don't have huge skip lists in
1717
//! the tests files. We test all their test suite, not only a few test.
1818
//!
1919
//! ## How to use the library

src/tests/bad_tests/ion_parser_bad_others.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::read_file_testsuite;
22
use crate::IonParserError;
33
use crate::ParsingError;
4-
use crate::{ion_parser::IonParser, binary_parser_types::ValueLength};
4+
use crate::{binary_parser_types::ValueLength, ion_parser::IonParser};
55
use bigdecimal::BigDecimal;
66
use std::fs::File;
77
use std::io::BufReader;
@@ -284,8 +284,8 @@ fn invalid_version_marker_in_annotation_wrapper() {
284284
let ion_element = read_file_testsuite!("bad/ivmInAnnotationWrapper");
285285
let mut parser = IonParser::new(ion_element);
286286
let value = parser.consume_value().unwrap_err();
287-
// Note, this error should be "NestedVersionMarker", but the binary file
288-
// provided by amazon has a wrong length.
287+
// Note, this error should be "NestedVersionMarker", but the binary file
288+
// provided by amazon has a wrong length.
289289
let expected = IonParserError::BinaryError(ParsingError::NoDataToRead);
290290
assert_eq!(expected, value);
291291
}

src/tests/binary_parser.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn decode_value_null() {
1010

1111
assert_eq!(
1212
lexer.consume_value_header(0),
13-
Ok(ValueHeader::new(0/*Null Value*/ + 15/*Len for null Value*/).unwrap())
13+
Ok(ValueHeader::new(0/*Null Value*/ + 15 /*Len for null Value*/).unwrap())
1414
);
1515
}
1616

@@ -350,8 +350,6 @@ fn decode_value_with_version_header() {
350350

351351
assert_eq!(
352352
lexer.consume_value_header(0),
353-
Ok(ValueHeader::new(
354-
(0xe << 4) /*Annotation*/ + 14 /*Long len*/
355-
).unwrap())
353+
Ok(ValueHeader::new((0xe << 4) /*Annotation*/ + 14 /*Long len*/).unwrap())
356354
);
357355
}

src/tests/good_tests/ion_parser_good_struct.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,11 @@ fn struct_ordered_in_list() {
116116

117117
assert_eq!(
118118
parser.consume_value().unwrap().0,
119-
IonValue::List(vec![
120-
IonValue::Struct(hashmap!(
121-
"version".to_string() => IonValue::Bool(false),
122-
"imports".to_string() => IonValue::Bool(true),
123-
"name".to_string() => IonValue::Null(NullIonValue::Null)
124-
))
125-
])
119+
IonValue::List(vec![IonValue::Struct(hashmap!(
120+
"version".to_string() => IonValue::Bool(false),
121+
"imports".to_string() => IonValue::Bool(true),
122+
"name".to_string() => IonValue::Null(NullIonValue::Null)
123+
))])
126124
);
127125
}
128126

0 commit comments

Comments
 (0)