Skip to content

Borrow, AsRef, others suboptimal for enums / specific structs #39125

@sdroege

Description

@sdroege

Consider something like the following two enums

enum Foo {
  Bar(i32),
  Baz(String),
}

enum FooBorrowed<'a> {
  Bar(&'a i32),
  Baz(&'a str),
}

In theory one would like to be able to implement Deref, AsRef, Borrow, IntoOwned, etc for this pair of enums (or a similar pair of structs) and e.g. also use it in a Cow. However that's not possible as Deref, AsRef, Borrow explicitly return a reference from their functions. If it was instead a "normal" type, one could implement it for the above pair and still cover the existing implementations that return references.

Is there any chance to extend this by new traits, or is there another solution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions