Skip to content

Commit

Permalink
jsonp: clippy::items_after_statements
Browse files Browse the repository at this point in the history
warning: adding items after statements is confusing, since items exist from the start of the scope
  --> src/cmd/jsonp.rs:75:5
   |
75 | /     fn df_from_stdin() -> PolarsResult<DataFrame> {
76 | |         // Create a buffer in memory for stdin
77 | |         let mut buffer: Vec<u8> = Vec::new();
78 | |         let stdin = std::io::stdin();
79 | |         stdin.lock().read_to_end(&mut buffer)?;
80 | |         JsonReader::new(Box::new(std::io::Cursor::new(buffer))).finish()
81 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
   = note: `-W clippy::items-after-statements` implied by `-W clippy::pedantic`
   = help: to override `-W clippy::pedantic` add `#[allow(clippy::items_after_statements)]`

warning: adding items after statements is confusing, since items exist from the start of the scope
  --> src/cmd/jsonp.rs:83:5
   |
83 | /     fn df_from_path(path: String) -> PolarsResult<DataFrame> {
84 | |         JsonReader::new(std::fs::File::open(path)?).finish()
85 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements

warning: adding items after statements is confusing, since items exist from the start of the scope
   --> src/cmd/jsonp.rs:98:5
    |
98  | /     fn df_to_csv<W: Write>(mut writer: W, mut df: DataFrame, args: &Args) -> PolarsResult<()> {
99  | |         CsvWriter::new(&mut writer)
100 | |             .with_datetime_format(args.flag_datetime_format.clone())
101 | |             .with_date_format(args.flag_date_format.clone())
...   |
107 | |         Ok(())
108 | |     }
    | |_____^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
  • Loading branch information
jqnatividad committed Jun 15, 2024
1 parent 7c7f3a8 commit c12ad87
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/cmd/jsonp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ struct Args {
}

pub fn run(argv: &[&str]) -> CliResult<()> {
let args: Args = util::get_args(USAGE, argv)?;

fn df_from_stdin() -> PolarsResult<DataFrame> {
// Create a buffer in memory for stdin
let mut buffer: Vec<u8> = Vec::new();
Expand All @@ -84,17 +82,6 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
JsonReader::new(std::fs::File::open(path)?).finish()
}

let df = match args.arg_input.clone() {
Some(path) => {
if path == "-" {
df_from_stdin()?
} else {
df_from_path(path)?
}
},
None => df_from_stdin()?,
};

fn df_to_csv<W: Write>(mut writer: W, mut df: DataFrame, args: &Args) -> PolarsResult<()> {
CsvWriter::new(&mut writer)
.with_datetime_format(args.flag_datetime_format.clone())
Expand All @@ -107,6 +94,21 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
Ok(())
}

// main

let args: Args = util::get_args(USAGE, argv)?;

let df = match args.arg_input.clone() {
Some(path) => {
if path == "-" {
df_from_stdin()?
} else {
df_from_path(path)?
}
},
None => df_from_stdin()?,
};

if let Some(output_path) = args.flag_output.clone() {
let mut output = std::fs::File::create(output_path)?;
df_to_csv(&mut output, df, &args)?;
Expand Down

0 comments on commit c12ad87

Please sign in to comment.