Skip to content

Conditional Bounds #5

Open
Open
@cramertj

Description

@cramertj

The ability to specify that an impl Trait return type only implements a trait if some other bound is met.

trait Foo {
   fn foo<T>(x: T) -> impl Debug + (Clone iff T: Clone);
}

As @Kimundi observed in the original impl Trait proposal, this common pattern can be seen in Rust's Iterator trait. Methods like chain return a type that is only Clone if Self: Clone and Other: Clone.

There's some discussion of this in the expanded impl Trait RFC, but I haven't seen any fully-fledged proposals for this yet.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions