Skip to content

enum state is very unergonomic (lens ergonomics?) #1418

@axelkar

Description

@axelkar

Example:

struct AState;
impl AState {
    fn ui_logic(&mut self) -> impl WidgetView<Self> + use<> {
        label("A")
    }
}

struct BState;
impl BState {
    fn ui_logic(&mut self) -> impl WidgetView<Self> + use<> {
        label("B")
    }
}

enum MyState {
    A(AState),
    B(BState)
}
impl MyState {
    fn ui_logic(&mut self) -> impl WidgetView<Self> + use<> {
        use xilem_core::one_of::Either;

        match self {
            Self::A(_a) => Either::A(lens(AState::ui_logic, |state: &mut Self| match state {
                Self::A(a) => a,
                _ => unreachable!(),
            }))
            Self::B(_b) => Either::B(lens(BState::ui_logic, |state: &mut Self| match state {
                Self::B(b) => b,
                _ => unreachable!(),
            }))
        }
    }
}

The same goes for matching Options and Results.

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