Skip to content

Conversation

@aaronshim
Copy link
Contributor

Fixes #1 .

Do we want to think about a further DRY optimization where we don't repeat the code that generates the statistics between the flat_writer and the json_writer paths? Perhaps another struct as an abstraction of the file -> stats computation that implements traits to_flat_writer and to_json_writer since only the representation of the stats computation are different?

@aaronshim aaronshim force-pushed the flags branch 2 times, most recently from 9b03403 to 1d7b71b Compare May 8, 2017 07:22
@aaronshim
Copy link
Contributor Author

aaronshim commented May 8, 2017

(Also, there are a lot of repeat commits from the fact that I branched this work off of an existing working branch off my fork, with pending changes in other PRs. Once the others go in, I will rebase this to get rid of duplicate commits.)

@aaronshim
Copy link
Contributor Author

Actually, totally found the answer to the whole "let's not leave a bunch of null keys in our JSON" story:

#[serde(skip_serializing_if="Option::is_none")]

It's talked about at serde-rs/serde#65.

@rowedonalde
Copy link
Owner

Finally getting around to this one, too. @aaronshim could you please rebase/merge from my master with the code from #11 that I just merged to clear up the duplicates and resolve the conflicts?

aaronshim added 2 commits June 1, 2017 23:14
(cherry picked from commit 41fa73ac17d62dddff1daef075bdef54d8da1e4f)
@aaronshim
Copy link
Contributor Author

Rebased and put in the serde serialization options to skip null.

@rowedonalde
Copy link
Owner

I've been traveling for a few days, so I'm just now taking a look at this--looks good so far.

// We will need to pass this down in the main thread, to the individual printers,
// and there is no point in passing down the whole Args struct, in the spirit of encapsulation.
#[derive(Debug)]
pub struct StatArgs {
Copy link
Owner

Choose a reason for hiding this comment

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

This feels a little un-DRY. For the sake of encapsulation, it definitely makes sense to pass the stat args around as their own struct, but I'm wondering whether there's a way we can eliminate the fields from Args that are later present in StatArgs. That way, we can either construct a full set of args using composition (which admittedly I haven't tried in Rust), or just see whether you can read into both structs with Docopt::new somehow.

(That, or we can just rename StatArgs to something that would make it conceptually distinct from command line arguments lol.)

// I wanted to prevent the evaluation of as many of these parameters at this level as possible
// but it seems that because compression rate depends on both .size() and .compressed_size(), we
// need both to be passed in to calculate compression_rate if needed. (No way to encode this
// dependency here without dependent types.)
Copy link
Owner

Choose a reason for hiding this comment

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

No problem

// all of these are going to be calculated, based on certain
// command-line flags given to this program.
//
// TODO: Figure out how to get the JSON serializer to dump fields
Copy link
Owner

Choose a reason for hiding this comment

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

Are you satisfying the TODO with the #[serde(skip_serializing_if="Option::is_none")]?

let multi_archive = MultiArchiveJsonWriter::from(file_paths,exclude);
serde_json::to_string_pretty(&multi_archive).unwrap()
fn zips_to_json_with_printer<F>(file_paths: &[&str], exclude: &str, stat_args: &StatArgs, printer: F) -> String
where F: Fn(&MultiArchiveJsonWriter) -> serde_json::Result<String> {
Copy link
Owner

Choose a reason for hiding this comment

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

Great refactoring using the where clause 💯

Copy link
Owner

Choose a reason for hiding this comment

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

I accidentally hit "start review" instead of just "single comment"--note that there are still comments, too


use zip_info::WriteZipInfo;
use zip_info::Args;
use zip_info::StatArgs;
Copy link
Owner

Choose a reason for hiding this comment

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

We can move all of these on one line using the shortcut described here.

use std::fs;

use zip_info::WriteZipInfo;
use zip_info::StatArgs;
Copy link
Owner

Choose a reason for hiding this comment

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

Same shortcut as in main.rs

@rowedonalde
Copy link
Owner

Other than my bikeshedding, it does what it says on the tin 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants