Skip to content
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

Type alias for generics #3528

Closed
Hapenia-Lans opened this issue Nov 13, 2023 · 2 comments
Closed

Type alias for generics #3528

Hapenia-Lans opened this issue Nov 13, 2023 · 2 comments

Comments

@Hapenia-Lans
Copy link

TL;DR, I want this:

type<T> SomeType = T: Copy + Clone + Debug + OtherTrait

// you can do this
impl<T> SomeTrait for SomeStruct<T>
where T: SomeType {
    ...
}

// also
impl<T: SomeType> SomeTrait for SomeStruct<T> {
    ...
}

I believe this will greatly enhance the readability of ultra-long generic constraints. This is just a little inspiration that I had while reading the source code of some crate. Any other solutions are welcome to comment here :)

@fmease
Copy link
Member

fmease commented Nov 13, 2023

Trait/bound aliases are more general than this and already account for your use case:

#![feature(trait_alias)]

trait SomeBound = Copy + Clone + Debug + OtherTrait;
// trait SomeBound = where Self: Copy + Clone + Debug + OtherTrait;

// you can do this
impl<T> SomeTrait for SomeStruct<T>
where
    T: SomeBound,
{
    // ...
}

// also
impl<T: SomeBound> SomeTrait for SomeStruct<T> {
    // ...
}

@fmease
Copy link
Member

fmease commented Nov 17, 2023

Closing in favor of RFC 1733 (tracking issue).

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants