Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
zslayton committed Jun 3, 2024
1 parent b2a4525 commit 80e8277
Show file tree
Hide file tree
Showing 8 changed files with 360 additions and 158 deletions.
4 changes: 2 additions & 2 deletions src/bin/ion/commands/beta/generate/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Language for JavaLanguage {
Blob | Clob => "byte[]",
SchemaDefined(name) => name,
}
.to_string()
.to_string()
}

fn target_type_as_sequence(target_type: &str) -> String {
Expand Down Expand Up @@ -129,7 +129,7 @@ impl Language for RustLanguage {
Blob | Clob => "Vec<u8>",
SchemaDefined(name) => name,
}
.to_string()
.to_string()
}

fn target_type_as_sequence(target_type: &str) -> String {
Expand Down
461 changes: 324 additions & 137 deletions src/bin/ion/commands/beta/inspect.rs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/bin/ion/commands/beta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ pub mod from;
#[cfg(feature = "experimental-code-gen")]
pub mod generate;
pub mod head;
pub mod inspect;
pub mod primitive;
pub mod schema;
pub mod symtab;
pub mod to;
pub mod inspect;

use crate::commands::beta::count::CountCommand;
use crate::commands::beta::inspect::InspectCommand;
use crate::commands::beta::from::FromNamespace;
#[cfg(feature = "experimental-code-gen")]
use crate::commands::beta::generate::GenerateCommand;
use crate::commands::beta::head::HeadCommand;
use crate::commands::beta::inspect::InspectCommand;
use crate::commands::beta::primitive::PrimitiveCommand;
use crate::commands::beta::schema::SchemaNamespace;
use crate::commands::beta::symtab::SymtabNamespace;
Expand Down Expand Up @@ -44,7 +44,7 @@ impl IonCliCommand for BetaNamespace {
Box::new(ToNamespace),
Box::new(SymtabNamespace),
#[cfg(feature = "experimental-code-gen")]
Box::new(GenerateCommand),
Box::new(GenerateCommand),
]
}
}
4 changes: 2 additions & 2 deletions src/bin/ion/commands/beta/symtab/filter.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::commands::{IonCliCommand, WithIonCliArgument};
use anyhow::{bail, Context, Result};
use clap::{Arg, ArgAction, ArgMatches, Command};
use ion_rs::*;
use std::fs::File;
use std::io;
use std::io::{stdout, BufWriter, Write};
use ion_rs::*;

pub struct SymtabFilterCommand;

Expand Down Expand Up @@ -94,7 +94,7 @@ pub fn filter_out_user_data(
SystemStreamItem::EndOfStream(_) => {
return Ok(());
}
_ => unreachable!("#[non_exhaustive] enum, current variants covered")
_ => unreachable!("#[non_exhaustive] enum, current variants covered"),
};
// If this is a text encoding, then we need delimiting space to separate
// IVMs from their neighboring system stream items. Consider:
Expand Down
19 changes: 14 additions & 5 deletions src/bin/ion/commands/beta/to/json.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::commands::{IonCliCommand, WithIonCliArgument};
use anyhow::{Context, Result};
use clap::{ArgMatches, Command};
use ion_rs::*;
use serde_json::{Map, Number, Value as JsonValue};
use std::fs::File;
use std::io::{stdin, stdout, BufWriter, Write};
use std::str::FromStr;
use ion_rs::*;
use zstd::zstd_safe::WriteBuf;

pub struct ToJsonCommand;
Expand Down Expand Up @@ -61,7 +61,10 @@ impl IonCliCommand for ToJsonCommand {
}
}

pub fn convert(reader: &mut Reader<AnyEncoding, impl IonInput>, output: &mut Box<dyn Write>) -> Result<()> {
pub fn convert(
reader: &mut Reader<AnyEncoding, impl IonInput>,
output: &mut Box<dyn Write>,
) -> Result<()> {
const FLUSH_EVERY_N: usize = 100;
let mut value_count = 0usize;
while let Some(value) = reader.next()? {
Expand Down Expand Up @@ -97,7 +100,8 @@ fn to_json_value(value: LazyValue<AnyEncoding>) -> Result<JsonValue> {
)
}
Timestamp(t) => JsonValue::String(t.to_string()),
Symbol(s) => s.text()
Symbol(s) => s
.text()
.map(|text| JsonValue::String(text.to_owned()))
.unwrap_or_else(|| JsonValue::Null),
String(s) => JsonValue::String(s.text().to_owned()),
Expand All @@ -122,7 +126,12 @@ fn to_json_value(value: LazyValue<AnyEncoding>) -> Result<JsonValue> {
Ok(value)
}

fn to_json_array<'a>(ion_values: impl IntoIterator<Item=IonResult<LazyValue<'a, AnyEncoding>>>) -> Result<JsonValue> {
let result: Result<Vec<JsonValue>> = ion_values.into_iter().flat_map(|v| v.map(to_json_value)).collect();
fn to_json_array<'a>(
ion_values: impl IntoIterator<Item = IonResult<LazyValue<'a, AnyEncoding>>>,
) -> Result<JsonValue> {
let result: Result<Vec<JsonValue>> = ion_values
.into_iter()
.flat_map(|v| v.map(to_json_value))
.collect();
Ok(JsonValue::Array(result?))
}
4 changes: 2 additions & 2 deletions src/bin/ion/commands/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ fn auto_decompressing_reader<R>(
mut reader: R,
header_len: usize,
) -> IonResult<AutoDecompressingReader>
where
R: BufRead + 'static,
where
R: BufRead + 'static,
{
// read header
let mut header_bytes = vec![0; header_len];
Expand Down
8 changes: 5 additions & 3 deletions src/bin/ion/file_writer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use termcolor::{ColorSpec, WriteColor};
use std::fs::File;
use std::io;
use std::io::{BufWriter, Write};
use std::fs::File;
use termcolor::{ColorSpec, WriteColor};

/// A buffered `io::Write` implementation that implements [`WriteColor`] by reporting that it does
/// not support TTY escape sequences and treating all requests to change or reset the current color
Expand All @@ -22,7 +22,9 @@ pub struct FileWriter {

impl FileWriter {
pub fn new(file: File) -> Self {
Self { inner: BufWriter::new(file) }
Self {
inner: BufWriter::new(file),
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,17 @@ fn test_write_all_values(#[case] number: i32, #[case] expected_output: &str) ->
let command_assert = cmd.assert();
let output = command_assert.get_output();
let stdout = String::from_utf8_lossy(&output.stdout);
assert_eq!(Element::read_all(stdout.trim_end())?, Element::read_all(expected_output)?);
assert_eq!(
Element::read_all(stdout.trim_end())?,
Element::read_all(expected_output)?
);
Ok(())
}

#[cfg(feature = "experimental-code-gen")]
mod code_gen_tests {
use std::fs;
use super::*;
use std::fs;

#[rstest]
#[case::simple_struct(
Expand Down Expand Up @@ -424,7 +427,8 @@ mod code_gen_tests {
let command_assert = cmd.assert();
let output_file_path = temp_dir.path().join(format!("{}.java", test_name));
command_assert.success();
let contents = fs::read_to_string(output_file_path).expect("Can not read generated code file.");
let contents =
fs::read_to_string(output_file_path).expect("Can not read generated code file.");
for expected_property in expected_properties {
assert!(contents.contains(expected_property));
}
Expand All @@ -433,4 +437,4 @@ mod code_gen_tests {
}
Ok(())
}
}
}

0 comments on commit 80e8277

Please sign in to comment.