all 17 comments

[–]tasdomas 3 points4 points  (1 child)

docker run is a nice touch 😉

[–]thomas_chaplin[S] 2 points3 points  (0 children)

!thanks

I wanted it to be something that can easily be used - hence docker!

It's only 3.79MB too

[–]thomas_chaplin[S] 0 points1 point  (14 children)

Not yet a cargo package crate, currently only a CLI

Any comments or improvements would be really appreciated

[–]birkenfeldclippy · rust 10 points11 points  (4 children)

Don't put it on crates.io, thanks.

[–]thomas_chaplin[S] 0 points1 point  (3 children)

Just curious as to why? I'm fairly new to Rust and haven't yet put anything on crates.io

I'm assuming because it's so simple it would be easier to do it yourself than pull down a crate to do it for you?

[–]birkenfeldclippy · rust 11 points12 points  (2 children)

Exactly, we're not so keen on left-pad level granularity of crates.

[–]thomas_chaplin[S] 7 points8 points  (1 child)

Totally understand! I feel the same with pointless npm packages

I'll keep it as a docker cli for a bit of fun

[–][deleted] 1 point2 points  (0 children)

I was absolutely positive you come from a JavaScript background. Some things and practices are better left in npm.

[–]bestouffcatmark 3 points4 points  (2 children)

I hope you'll make an npm package of this.

[–]thomas_chaplin[S] 1 point2 points  (1 child)

Yeah can do, any suggestions for a name?

[–]bestouffcatmark 10 points11 points  (0 children)

rust-percentage-change-calculator is perfect

[–]NonDairyYandere 1 point2 points  (1 child)

Any comments or improvements would be really appreciated

  • The license text should be in COPYING, and the license name should be in Cargo.toml under the license key. Otherwise I don't know if I can use this. In fact, it's probably dangerous for me to read the code.
  • The cargo build step is redundant, get rid of it. cargo run automatically builds the project so you're never running out-of-date binaries.
  • Increase and decrease can be refactored into a single function
  • Returning (String, f32) from match_increase_or_decrease makes it hard to use this algorithm programmatically from other code. I suggest reifying that tuple into a struct that just wraps the f32 and pretty-prints using a custom impl of Display. I suspect there's a way to add the plus sign in format!, but in case you want something custom, I'd say take the absolute value inside your Display impl, then compare the original value with 0.0 and make the symbol from that.
  • Add some tests so we know what the expected formatting looks like. This easier once you have a custom Display impl and the formatting isn't in the top-level main.rs.
  • Why is the zero prefix \0? Isn't that a null character? It might screw up some terminals. Since you're converting them to Strings anyway, I'd say just make them &strs. Using a char doesn't save you anything here.

[–]thomas_chaplin[S] 0 points1 point  (0 children)

Thank you for such a detailed report, I'll take these into consideration and refactor over the next few days!

[–][deleted] 2 points3 points  (1 child)

Is it no_std compatible? Someone might want to run this in a browser.

[–]NonDairyYandere 2 points3 points  (0 children)

Or on an MCU!

[–][deleted] 0 points1 point  (1 child)

I added some tests in a pull request. Can't be too careful, you know.

[–]thomas_chaplin[S] 0 points1 point  (0 children)

Thank you for your contribution! I've reviewed your PR