Skip to content

Commit

Permalink
formatting cleanup, set ion_rs dep to v1.0.0-rc.5
Browse files Browse the repository at this point in the history
  • Loading branch information
zslayton committed Jun 3, 2024
1 parent 592c27f commit e59676d
Show file tree
Hide file tree
Showing 11 changed files with 510 additions and 312 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ clap = { version = "4.0.17", features = ["cargo"] }
colored = "2.0.0"
flate2 = "1.0"
infer = "0.15.0"
ion-rs = { version = "1.0.0-rc.4", features = ["experimental"] }
ion-rs = { version = "1.0.0-rc.5", features = ["experimental"] }
tempfile = "3.2.0"
ion-schema = "0.10.0"
serde = { version = "1.0.163", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion src/bin/ion/commands/beta/generate/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::Serialize;
use std::fmt::{Display, Formatter};

/// Represents a field that will be added to generated data model.
/// This will be used by the template engine to fill properties of a struct/classs.
/// This will be used by the template engine to fill properties of a struct/class.
#[derive(Serialize)]
pub struct Field {
pub(crate) name: String,
Expand Down
480 changes: 330 additions & 150 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
22 changes: 16 additions & 6 deletions src/bin/ion/commands/beta/to/json.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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 @@ -60,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 @@ -96,13 +100,14 @@ 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()),
Blob(b) | Clob(b) => {
use base64::{engine::general_purpose as base64_encoder, Engine as _};
let base64_text = base64_encoder::STANDARD.encode(b.as_ref());
let base64_text = base64_encoder::STANDARD.encode(b.as_slice());
JsonValue::String(base64_text)
}
SExp(s) => to_json_array(s.iter())?,
Expand All @@ -121,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
Loading

0 comments on commit e59676d

Please sign in to comment.