-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
A-implsImplementations related proposals & ideasImplementations related proposals & ideasA-syntaxSyntax related proposals & ideasSyntax related proposals & ideasT-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.
Description
Currently impl for a struct and traits look like this:
struct Services {};
impl Services {
}
impl Clone for Services {
fn clone(&self) -> Services {
Services {}
}
}Now if we add lifetimes, and/or generics, the syntax gets out of hand rather quickly.
struct Services<'a, T> { wrap_drive: &'a WarpDrive<T> };
impl<'a, T> Services<'a, T> {
}
impl<'a, T> Clone for Services<'a, T> {
fn clone(&self) -> Services<'a, T> {
Services {
// ..
}
}
}What I'm proposing is to be able to write this instead:
struct Services<'a, T> { wrap_drive: &'a WarpDrive<T> };
impl<'a, T> Services<'a, T> {
fn beam_all_services() { }
// ..snip..snip
impl Clone for Self {
fn clone(&self) -> Services<'a, T> {
Services {
// ...
}
}
}
}Advantages:
- Reduce boiler plate for
implwhen it's an in-module struct. - Encourage in-module blocks to be cleanly encapsulated into the parent impl block, allowing for easier source comprehension and maintenance.
- While the above is a trivial case, code bases like actix and Hyper which makes heavy use of generics can be made much more readable removing redundant type information from each impl blocks.
- This is all entirely optional. So, no breaking changes.
Disadvantages:
- impls are no longer just confined to the top-level, but also be one level nested.
- Compiler complexity.
LifeIsStrange, stijnh, jerielverissimo, mankinskin, fxdave and 2 moreH2CO3, SephVelut, shekohex and kennytm
Metadata
Metadata
Assignees
Labels
A-implsImplementations related proposals & ideasImplementations related proposals & ideasA-syntaxSyntax related proposals & ideasSyntax related proposals & ideasT-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.