implement inherent associated items (see RFC 195). #8995
Comments
Nominating; is backwards compatible. I can try and take this on if we decide we want it. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
assigning P-low priority (is backwards compatible going foward, as cmr said). |
Triage: How does this interact with Associated Types? At least a new syntax would probably have to be chosen. |
I think that this feature request is actually satisfied by the Associated Items RFC. In particular, the section "inherent associated items" of RFC 59 implies (to me) that you can write the exact example that I had asked for. (I did write in the issue description that this feature request is distinct from associated types, but nonetheless, it seems that the author of RFC 59 decided that it was a natural feature to include.) |
So, this now seems to be a subissue of #17307. I will change the title to "implement inherent associated items." |
Hello, I hope this the right place to ask for my request. Associated types currently only work with traits. pub struct GenericStruct<A, B> {
fa : A,
fb : B,
}
struct GenericResult<A, B> {
fa : A,
fb : B,
}
impl <A, B> GenericStruct<A, B> {
// I d like to write
// type Result = Option<GenericResult<A, B>>;
// and use it in the code
fn new(a: A, b : B) -> Option<GenericResult<A, B>> {
Some(GenericResult {fa: a, fb : b})
}
} |
I'm going to tag this with the tags from #8995 since it was closed without this being implemented. |
@steveklabnik I think you meant to reference #17307 rather than #8995, which is this issue. |
note that inherent associated consts work perfectly fine today
|
@nikomatsakis Is it right to assume that this can't be implemented without lazy normalization? |
It would be good to link to this issue in the error message for https://doc.rust-lang.org/nightly/error-index.html#E0202, as it's not immediately clear that this is supposed to be supported. |
Any developments on this lately? |
Nevermind. What I was trying to do works. I just put "impl MyStruct" instead of "impl MyTrait for MyStruct"... |
Blocked on #60471 (Lazy normalization). |
Collapse PreFilters and PostFilters into the single type and implementation using the associated type (Descriptor) for distinguishing between commit evaluation stages and to group filters into chains per single stage. The calling code may be simplified even more as soon as associated types will be allowed in inherent implementations: rust-lang/rust#8995
Any updates? |
It would be great to get this in some form, it can make generic programming a lot easier. Suppose I have a generic struct, and I need to implement several functions on it which all refer to the same "complex" type in their return parameters or arguments, and the type depends on generic parameters. This is a pretty common situation. Naturally I'd like to give that type a nice name and avoid typing it repeatedly. But, there is no where for that declaration to go if it depends on the generic parameters of the struct.
It seems I have to either It's frustrating because in other languages there are better ways |
This issue is tracking RFC 195's inherent associated items
Original description follows.
When developing a type-parametric impl, I found myself writing code somewhat like this:
I cannot make a
type
definition forHashMap<NT, ~[Prod<T,NT>]>
outside of theimpl
because it then those free references toNT
andT
would be unbound.And I cannot put a
type
definition within the impl, even an impl for a struct such as this (it simply does not parse with the current grammar).(Being able to put type definitions within impls will probably arise naturally from #5033, when we get around to that. But that is nonetheless a separate issue from this: Associated Types (and Associated Items) are about enabling certain patterns for the user of a trait, while this ticket describes a convenience for the implementor of a struct.)
Implementation History
The text was updated successfully, but these errors were encountered: