News for hackers. Stuff that matters.
Re:Switching from C++ to Rust by zaphar on Tuesday March 14, 2023 @08:12AM (#35150221)
It's not exactly what you want but you get most of the benefit by just wrapping types in enum variants.
Re:Switching from C++ to Rust by evntdrvn on Tuesday March 14, 2023 @11:34AM (#35153197)
Thanks yeah, I was just meaning for the ergonomics aspect :) Cheers
Re:Switching from C++ to Rust by estebank on Tuesday March 14, 2023 @06:09PM (#35159696)
It's a request for the following to be valid

    enum X {
        A,
        B,
    }
    fn foo() -> X::A {
        X::A
    }
which helps a lot when composing state machines. In the meantime, you can indeed do what you propose:

    enum X {
        A(Foo),
        B(Bar),
    }
    struct Foo;
    struct Bar;
    fn foo() -> Foo {
        Foo
    }