Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for TryFrom/TryInto traits #33417
Comments
alexcrichton
added
B-RFC-approved
T-libs
labels
May 4, 2016
sfackler
added a commit
to sfackler/rust
that referenced
this issue
May 5, 2016
sfackler
added a commit
to sfackler/rust
that referenced
this issue
May 5, 2016
sfackler
added a commit
to sfackler/rust
that referenced
this issue
May 7, 2016
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
May 8, 2016
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
May 8, 2016
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
May 8, 2016
This comment has been minimized.
This comment has been minimized.
|
Is there a way to generically print an error with the original value if the conversion fails without requiring |
This comment has been minimized.
This comment has been minimized.
|
A discussion of whether this should go in the prelude is pending for when this goes stable. |
alexcrichton
added
B-unstable
and removed
B-RFC-approved
labels
Jun 21, 2016
This comment has been minimized.
This comment has been minimized.
|
Apologies if this is covered somewhere else, but what would we like to see before marking this as stable? I'm pretty sure I've reimplemented this functionality a few times in various projects, so a common reusable trait would make me |
sfackler
added
the
I-nominated
label
Jul 9, 2016
This comment has been minimized.
This comment has been minimized.
|
We can bring it up for discussion for the next cycle. |
alexcrichton
added
final-comment-period
and removed
I-nominated
labels
Jul 13, 2016
This comment has been minimized.
This comment has been minimized.
|
As a point of stabilization, the libs team would also like to add these traits to the prelude as part of their stabilization. This will require a crater run being 100% clean at minimum, but we're relatively confident that the current state of resolve makes it backwards compatible to add traits to the prelude. |
This comment has been minimized.
This comment has been minimized.
|
I have a few questions about the purpose of these traits.
|
This comment has been minimized.
This comment has been minimized.
|
cc @sfackler, could you expand on the current set of impls and some of the rationale as well? |
This comment has been minimized.
This comment has been minimized.
|
I think in general the intuition should be exactly the same for that of In general, I don't think it should be expected that all types should |
This comment has been minimized.
This comment has been minimized.
When a |
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin that would break an |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@sfackler Not if you use plain |
This comment has been minimized.
This comment has been minimized.
That doesn't appear to have happened yet so I don't know if it's because nobody has got round to it or there are no applicable types in
The issue is that if you want to use
Does this mean the error type is somehow fixed based on the type you're converting to? |
This comment has been minimized.
This comment has been minimized.
|
Why |
This comment has been minimized.
This comment has been minimized.
marco9999
commented
Feb 3, 2019
•
|
Sorry if this is the wrong place, but looks like there is a mistake in the docs for TryFromIntError - it lists Is there meant to be a |
This comment has been minimized.
This comment has been minimized.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct TryFromIntError(());It's got a |
This comment has been minimized.
This comment has been minimized.
marco9999
commented
Feb 3, 2019
|
Hmm yea there is... is something not working properly?
|
This comment has been minimized.
This comment has been minimized.
|
@marco9999 You're probably missing a generic constraint.
Anyway, this is a bit out of topic, sorry everyone. IRC might be a better place to ask these questions. |
This comment has been minimized.
This comment has been minimized.
@icefoxen There's no useful value associated with
This seems reasonable to me. |
This was referenced Feb 5, 2019
pietroalbini
added a commit
to pietroalbini/rust
that referenced
this issue
Feb 10, 2019
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this issue
Feb 10, 2019
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this issue
Feb 10, 2019
prataprc
referenced this issue
Feb 12, 2019
Open
Implement TryFrom and TryInto trait to convert Json to T. #12
This comment has been minimized.
This comment has been minimized.
|
Cross-referencing: #58302 |
This comment has been minimized.
This comment has been minimized.
|
Thanks @glaebhoerl. Due to a blocking bug being fixed (#49593) I was hoping that the never type could be stabilized Soon® #57012 and unblock this. However a new issue (#57012 (comment)) has come up, and we also don’t have consensus on another one (#57012 (comment)). So in a libs meeting last week I brought up again the idea, I believe first proposed by @scottmcm in #33417 (comment), to stabilize Last time we discussed this (#33417 (comment)), we couldn’t remember why we hadn’t done this the previous time. Last week @dtolnay reminded us of the issue: before use std::convert::Infallible;
trait MyTrait {}
impl MyTrait for fn() -> ! {}
impl MyTrait for fn() -> Infallible {}Because So changing the enum to an alias would be a breaking change. On principle we wouldn’t allow it in the standard library, but in this case we felt that:
Based on this discussion, I submitted #58302 which is now in Final Comment Period. |
This comment has been minimized.
This comment has been minimized.
|
#58015 should be ready for review/merge now. |
This comment has been minimized.
This comment has been minimized.
|
@kennytm Isn't it possible to refer to trait MyTrait {
type Output;
}
impl<T> MyTrait for fn() -> T {
type Output = T;
}
type Void = <fn() -> ! as MyTrait>::Output;After doing this, |
This comment has been minimized.
This comment has been minimized.
|
That looks like a bug, which means stability guarantees don't extend to it. Using the never type ( |
This was referenced Feb 25, 2019
bors
added a commit
that referenced
this issue
Feb 25, 2019
bors
added a commit
that referenced
this issue
Feb 25, 2019
Centril
added a commit
to Centril/rust
that referenced
this issue
Feb 28, 2019
Centril
added a commit
to Centril/rust
that referenced
this issue
Feb 28, 2019
mauricekayser
referenced this issue
Mar 11, 2019
Closed
Add core::convert::TryInto<Primitive> implementation for Expr #604
This comment has been minimized.
This comment has been minimized.
bartsmykla
commented
Mar 12, 2019
|
How can I help with documentation? :-) |
This comment has been minimized.
This comment has been minimized.
|
Oh I thought #58015 had landed, but it hasn’t yet… Let’s discuss it there. |
bors
added a commit
that referenced
this issue
Mar 12, 2019
This comment has been minimized.
This comment has been minimized.
|
Could fn check(value: &T) -> bool |
This comment has been minimized.
This comment has been minimized.
|
One way to work with non-consuming impossible conversion could be to return the consumed non-convertible value along with the associated error. |
alexcrichton commentedMay 4, 2016
•
edited by SimonSapin
Tracking issue for rust-lang/rfcs#1542
To do:
TryFromblanket impl to useIntoinstead ofFrom