-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Base64 XML variants #16586
Base64 XML variants #16586
Conversation
Due to the change to |
It seems strange for |
This commit changes the signature of the main method in the FromBase64 trait, as the existing code did not take config into account and relied on an assumptions that are not true for all configs (i.e. that every Base64 charset uses `-` for 0x3e and `_` for 0x3f). This change makes the base64 API more symmetric and allows for future changes to `from_base64` to make it more RFC-compliant. [breaking-change]
@alexcrichton: thanks for the reminder. I have now changed the commits to mention the API change as described in policy and pushed the new commits. @sfackler: it is not that strange. First it brings back a bit of simmetry to the base64 API. But more importantly, the fact that it uses only one field is because it is not yet complete: in order to be RFC compliant it should raise an error when it sees no newline in a config that requires the presence of newlines. |
May I have a review on this minor PR, now that the commit messages have been fixed as requested? |
Thanks for updating the commit message @gioele, that looks great! I'm also a little uncomfortable in putting the config in the commonly-used Looking around at other languages, it looks like Ruby has separate methods for each flavor of encode/decode, Go has separate encoder/decoder structures, Java has separate methods, and python has separate methods. Usability-wise I don't think passing in a config is the best way to go, and it seems like the trends in other languages is not to have one method that takes configuration. |
Thanks for the review, @alexcrichton. I agree that having a mandatory Talking of API in other design, I would like this method to work like
If one wants to convert that number to a string, but using another base, they can add the
This kind of API requires the possibility to have default parameters, something that Rust does not have at the moment IIUC. Two concrete possibility for the API of
I think this is the best kind of API as long as default parameters cannot be used. Should I go forth and implement one of these designs? |
Sorry for being a little slow to getting back to you! It looks like the trend of other languages is to either have a separate encoder/decoder for each type of base64 encoding (a separate trait for us) or a separate pair of methods. I personally find the So I suppose to speak concretely, I would advocate for something like: trait Base64Decode {
fn decode_base64(...);
fn decode_base64_url(...);
fn decode_base64_xml(...);
} Or something along the lines of that. This should get another opinion though as I'm sure others would differ! |
The use of As far as In any case, I agree with @sfackler that the decoding methods shouldn't take a |
I see the Builder patter overcomplex for a Base64 transformation, especially because it would force the addition of one method for each supported type from which you can encode/decode. And BTW, the Java API is not exactly a model to follow for ergonomic interfaces. :) Here is my proposal, based on what @alexcrichton suggested: a
|
@gioele Sounds good to me! |
Closing due to inactivity, but feel free to reopen with an updated PR! |
…kril fix: Remove cargo knowledge from `CrateData` Fixes rust-lang/rust-analyzer#16170, Fixes rust-lang/rust-analyzer#15656
These two commits implement two variants of Base64 used when the result is to be used as part of an XML element name or as a NMTOKEN.
The second commit changes the signature of the main method in the
FromBase64
trait, as the existing code did not takeconfig
into account and relied on an assumptions that are not true (i.e. that every Base64 charset uses-
for 0x3e and_
for 0x3f).