-
Notifications
You must be signed in to change notification settings - Fork 185
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
Fix consistency of from_bytes, try_from_bytes, from_str, try_from_str #4931
Comments
I think I like the So my suggestion is:
These methods would have to be renamed to follow that scheme:
These methods should be
|
I roughly agree with Robert's stance with the caveat that I'm not a huge fan of having inherent methods named the same as trait methods that are implemented by the type (so the "name something the same to get it const" is not that great, for me) |
I strongly prefer using
I consider Also, people don't usually call Anecdotally, I have found it misleading when the only constructor for various ICU4X types is
|
@Manishearth If you hold this position, should we reconsider #4590? |
This is problematic because the signature is different than the trait function How about this revised proposal:
|
I'm fine not implementing FromStr in the infallible case. |
Actually I'm wholly against
We actually use
|
I think Suggestion:
We don't need to implement all of them for all constructors - just normalize the naming scheme so that we can introduce the ones we find useful incrementally. |
+1 on using |
It's a very weakly held position, I think #4590 is okay. I'm also fine with the proposal here for similar reasons. |
I'm working on locid now in context of icu_preferences, and once I'm done I'd like to unify and improve docs on handling of to/from u8/u16/str for all subtags for preparation for locid &[u16] handling. Any thoughts on my proposal several comments above? |
Concrete proposal: All types that are fallibly created from a string have the following functions:
All types that are infallibly created from a string have the following functions:
|
I didn't realize I signed off on the "(only ever called through parse in documentation, but only if it can be done without turbofishes, otherwise Foo::try_from_str)" -- I agree with the "only ever called through parse in documentation" but not necessarily the "only if it can be done without turbofishes" |
LGTM with the same alternation as @sffc pointed ou in the last comment. I'm not convinced that turbofish specifier is bad enough to have a blank rule against it in docs. |
Introduces TinyAsciiStr constructors from utf16 and converges on the consensus from #4931. --------- Co-authored-by: Robert Bastian <[email protected]>
What about this pattern: pub struct Era(pub TinyStr16);
impl From<TinyStr16> for Era {
fn from(x: TinyStr16) -> Self {
Self(x)
}
}
impl FromStr for Era {
type Err = <TinyStr16 as FromStr>::Err;
fn from_str(s: &str) -> Result<Self, Self::Err> {
s.parse().map(Self)
}
} Both the |
#4931 Covers all types that had a `try_from_bytes`. There are still a lot of types that implement `FromStr`, but don't have any inherent methods. Those will be next.
This is done for all stable components and utils, except for the datetime and plurals reference and runtime modules. |
@zbraniecki WDYT about doing the facelift to those modules? |
Also in 2.0 (can be stretch), apply this style to all stringy APIs such as canonicalize, normalize, ... |
I think we should align them with the decision here. |
Conclusion:
LGTM: @sffc (@robertbastian) @Manishearth |
@robertbastian How much of this is done? Does this just need a final audit, or are there pieces that still need doing? |
No change since the last update from me. |
Blocked on #5181 |
@robertbastian is that the only case? I'd say we can close this issue then. |
Again, #4931 (comment) |
|
Assuming #6103, I think we can close this out once that lands. |
That landed, nothing left is in stable code. |
In our docs there are 95 and 63 hits for
from_bytes
andtry_from_bytes
(the former includes counts from the latter), and there's also a mix offrom_str
andtry_from_str
.We should try to fix this in 2.0. I suggest:
try_from_bytes
andFromStr::from_str
. In the cases where they are not fallible,from_bytes
is fine.Alternatively, we could rename everything to
try_from_utf8
instead oftry_from_bytes
.EDIT: I think my preference has changed to also include
try_from_str
constructors. See discussion.Feedback needed from:
The text was updated successfully, but these errors were encountered: