-
Notifications
You must be signed in to change notification settings - Fork 5
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
Possible to add value_as_str? #15
Comments
Instead of matching all different suffixes, you can just call Is that what you are looking for? Would you still say that functionality should be added as function? I will probably add some docs about the "largest integer trick". |
Thanks for the reminder, I got hit by exactly this after opening the issue, and fixed it by going with the trick you later mentioned (weirdly, I already had
Yes, I think the user should not need to learn about these Rust grammar quirks, and also think number is an important part for it be easily extracted just like other chunks like base. |
Can you quickly explain what you will do with that resulting string? How are you using that? |
Sure. I store the result in a key-value database so that I can retrieve it later in a script (and use it as an embedded database in a dll). The original strings are win32 API constant values that I get from parsing rustdocs for a Windows sys crate (which seems like the easiest way to get them). I use your crate to then convert those string constant values to a "clean" non-suffixed-non- So ideally I'd have a single and simple (in a potentially better future I might need to retain the numeric types instead of using strings, that's where the no-sign parsing will bite again and require separate handling in addition to separate matching, but that's a different issue) |
I've thought about this whole I also decided against I do agree though that these features are very useful to have generally. I just think they should live in a different crate. I might even build one as I have use for it as well (e.g. in Sorry for the probably disappointing outcome! |
If you have various primitive types in a string form from rustdocs (like
5_000i32
etc) and want to extract the5000
without any_
(for this case a string output is fine), you can parse the strings withpub fn value<N: FromIntegerLiteral>(&self) -> Option
But then this ignores the existing suffix
so it requires matching for all the valid suffixes to get the type N (and account for the weird fact that
f32
isn't a float, but an integer, so you shouln't forget that suffix in the integers)The alternative to get the string directly...
pub fn raw_main_part(&self) -> &str
...ignores the base
Would it be possible to add a function that would allow extracting the number accounting for the base and not requiring enumerating all the suffixes?
The text was updated successfully, but these errors were encountered: