Skip to content
This repository was archived by the owner on Sep 15, 2026. It is now read-only.
This repository was archived by the owner on Sep 15, 2026. It is now read-only.

"Expect" getters #6

Description

@alekratz

Would it make sense to have a getter that returns a Result<&T, E>? e.g.

#[derive(EnumExpectGetters)]
enum MyEnum {
    Foo(i32),
    Bar(String),
}

fn main() {
    let foo = MyEnum::Foo(i32);
    let oops = "You can't do that!";
    assert_eq!(foo.expect_bar::<&str>(oops), Err(oops));
}

or something like that? The only major problem I can immediately see is with it conflicting with result types that have one or both type parameters filled out (e.g. error-chain or std::io::Result).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions