-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing? #4
Comments
Hey again! Humm, that's different, but I can do it too... assert_eq!("123.5kPackets".parse().unwrap(), HumanCount::new(123500_u32, "Packets")); Anyway, I'll do this after serde, because this seems to require much more work (tests...). |
Hey! Thanks again for considering it! Yes, the example was kinda weird... I don't mind a completely different approach, my main interest here is that I can parse 😄 Depending on how you approach things, it might be worth doing it exactly the other way round, because the serde functionality (#3) would require parsing for its But whatever way you prefer! 😆 |
Hey, please explain exactly why would you need this... |
Because if it is used in some configuration file, say: duration = "12ms" a user might want to parse that. Of course now that the crate implements serde, offering parsing is not more than exposing that basic building block from serde in the API of the crate, I guess. Exposing the parsing bits from the serde implementation would also offer the possibility for users to implement interactive programs. For example where a user is asked interactively how much a program should wait before retrying, and they can insert "1 minute" in a text-field. |
I just looked at how the serde compat was implemented,... it was not implemented as I intended. What I intended was that I can have a TOML file like this: duration = "12ms" And a struct like this:
And parse the former to the latter. What I would need to specify with the current implementation is [duration]
val = 12.0
unit = "ms" Which is different than what I had intended. |
EDIT: I'm implementing it. |
On the yesterday's serde release, I put a section about an example of how to use this, look: use human_repr::{HumanCount, HumanDuration, HumanThroughput};
let now = std::time::Instant::now();
let updated = 3431237; // process something...
println!("Updated {} successfully.", updated.human_count_bytes());
println!("Operation took {}.", now.elapsed().human_duration());
println!("Rate: {}", (updated as f64 / now.elapsed().as_secs_f64()).human_throughput_bytes()); See, human-repr is the helper to make beautiful logs or state messages to inform a user what some program did. I did implement serde, but actually, if one needs to persist or transfer e.g. a HumanCount, one could generate the beautiful data representation it provides and just use that. |
Hey @matthiasbeyer, you may have noticed I left this issue open... |
Hi! Would be really nice if this crate would support parsing as well!
E.G:
Or something like this.
The text was updated successfully, but these errors were encountered: