sort -h friendly output mode
As of now an extremely ugly variant to get in #14. Works, though. Please review.
@hyunsik The Travis failure is due to:
$ cargo fmt --all -- --write-mode=diff
Unrecognized option: 'write-mode'
Hi @wookietreiber,
I'm sorry for a late response. I missed your issue and this PR from a lot of email deluge. I'll fix the travis issue and review your PR by tomorrow. Thank you for your contribution!
I've also fixed the build error at https://github.com/hyunsik/bytesize/commit/9d8e13f05fe2fb2596a5534e86ef135af5bae6a3.
Thanks for catching the println statements. Rebased.
At the moment, I added a new function to_simple_string_as to ByteSize and a new argument to the to_string stand-alone function. Note that this can be done differently, e.g. adding the simple: bool argument to the to_string_as function on ByteSize and dropping the to_simple_string_as. Both of these variants, though, have implications regarding compatibility and would require a semver bump to the next major version.
It could also be done completely compatible by creating a new stand-alone to_string_simple function as well. But this wouldn't be as clean anymore.
I don't know which way you'd prefer. Please advise.
Hi,
I'm sorry for a late response. The simple representation seems to lose a unit of measurement. I think that your approach is a good option.
I also have another suggestion that implement functions to result in float values in different unit of measurements. For example,
pub fn as_mb(&self) -> f64 {
...
}
pub fn as_mib(&self) -> f64 {
...
}
pub fn as_gb(&self) -> f64 {
...
}
pub fn as_gib(&self) -> f64 {
...
}
...
Then, this approach will allows users to handle more various use-cases including your case. What do you think about that?
I guess, I would prefer an even higher-level approach:
enum OutputFormat {
SI, // 1000, e.g. "32 KB"
IEC, // 1024, e.g. "32 KiB"
Sort, // 1024, e.g. "32K"
}
fn to_string(b: ByteSize, fmt: OutputFormat) -> String {
// ...
}
@hyunsik I've finally gotten around to implementing my idea from my last comment.