-
Notifications
You must be signed in to change notification settings - Fork 17
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
Duplicate effort? #3
Comments
That looks like a much more complicated format than the python/rust format function/macro. It looks to contain logic within the text itself (not just formatting logic, but actual logic). The below is quite different from rust
|
I like their inteligent use of macros and the precompiling step -- I will be sure to add these things to improve speed for some use cases. |
It is still a strict superset of the python/rust format function/macro. Nobody forces anybody to use the select and plural formats. They come handy sometimes though.
Macros are icing on the top. Most important is to get rid of the HashMap, which is unwieldy and not particularly efficient either. Made worse by the I would personally prefer the underlying syntax like: strfmt("hi, my name is {name} and I am a {job}!").arg("name", "Bob").arg("job", "python developer").to_string() (or I proposed how to build a list on stack without allocation in endoli/message-format.rs#2, which still uses dynamic dispatch. There is a more refined version with all static dispatch at http://src.codes/typed-linked-lists.html, but I suspect the code increase due to having to generate the formatting function for each combination of parameters would be worse than the dynamic dispatch.
While it is likely beneficial for the complex formats like … except maybe you could. If you used the typed list idea, and made the parsing function generic in its complete type, you could. But it would also limit you to positional parameters, because Rust does not have a reasonable way to encode name in the type (hopefully yet). |
I'm not seeing how that language can handle format args like: The format arg syntax would be nice for putting it in a macro, maybe it could be something like the constructor:
This would allow you to build up all the arguments and format in one go, or create your formatters and format one at a time.
I can easily precompile the argument formats, it is the on the onus of the user of strfmt_map to handle the types correctly. I could easily accept a list of something like this as well:
I'm not sure what is the best option (I'm tempted to leave it to the user of Of course, the |
Basically in ICU documentation the placeholder for argument is described to be, generally, of the form
The Rust version should combine the two, because dates, times and money amounts should all be represented by their dedicated types, not plain numbers, so there is no need for
No, no, no. Just "hi, my name is {name} and I am a {job}! I have {cats} cats!"
.fmt_arg("name", "Bob")
.fmt_arg("job", "python developer")
.fmt_arg("cats", 42)
.fmt_args() There should be a trait that will work similarly to trait Formattable {
fn fmt(&self, fmt: &str, out: &mut std::fmt::Formatter) -> Result<(), SomeError>
} I am just writing such trait in https://github.com/rust-locale/rust-locale/tree/next (it's not there yet; I am still working on it). However, that one will only support things relevant for localization, so only decimal format, and in future possibly rule-based words format (so 42 would be formatted as "fourty two").
IMO the best option is to accept a trait. In fact, I am planning to propose, for message-format, to add yet another level of genericity so it can be adapted to different traits. |
How do you precompile them? A number format might look like So how do you want to interpret the pattern if you don't know the type yet? Of course all this assumes that you make the type extensible. If you make an enum of supported types, you will know all possible formats. But I would consider such library basically useless. |
According to this, I would think the format would be something like:
That is assuming that message-format could handle the exact same formatting options (which you say it can). It would be nice if it could handle either. For instance, if it could handle python/rust fmt if there was a
It is the "fill character"
If it accepted a trait, I would want it to default to being able to accept the Overall I really like the idea of using the trait. I don't see why you are passing the full |
Well, currently, they don't. However I am working on that for locale and will be integrating some message formatting with it. And while I feared the plural and choice formats may be too taxing on the translators, I was assured they come in handy. I suppose it depends on how good translators you can afford; you don't have to use them if you have less techinical translators.
I believe it requires rust-lang/rfcs#1210, which is tracked by rust-lang/rust#31844. That is unfortunately still open, but the main part implemented in rust-lang/rust#30652 already landed and, if I understand the annotation on github correctly, made it into 1.9.0. With that, it is possible to
The reason is that different types need to recognize different format specifications. The simple There could be some common handling for the fill and width, but at least there needs to be an option for more than one letter for the style. Well, I do see another option for dates and times. I can imagine format like |
Ah, yes I think you might be right. I followed that issue but I didn't think it could be used for this. I think the main problem is that Possibly if we could replace
From my experience, not properly deserializing data is the root of all sorts of bugs and problems. I think that not serializing would be a grave mistake. I could discuss with you some possibilities of how message-format could be structured that allows you to do this (things like having embeded structs come to mind). Issue point Outside of that, I think the goals of message-format and strfmt are very different. In the places that they converge, I think they should -- and we should work together to creating a unified We should open separate issues for implementing the various functionality that we have discussed in this thread. However, I do not think the topic of this dicussion is correct: while message-format and strfmt may partially overlap, strfmt aims to be a wholly simpler format that is fully compliant with the python format string. If it ever comes to be that strfmt's functionality can be completely handled by message-format, then we should merge them, and strfmt can just be a layer on top of message-format. Until then, we should only merge them in the areas that they can work together (like we could make a formatlib for storing this Trait) Thanks. I will be opening some issues to reference these, and you are welcome to as well! |
There is also https://github.com/endoli/message-format.rs with apparently similar goals.
The text was updated successfully, but these errors were encountered: