Skip to content

Implement From<PinState> for boolΒ #427

@sourcebox

Description

@sourcebox

From<bool> is already implemented for PinState in digital.rs, which makes sense for output pins. For input pins, it would make sense to implement the Into<bool> trait as well, so a function could take an argument that is either a PinState or a bool:

impl Into<bool> for PinState {
    fn into(self) -> bool {
        match self {
            PinState::Low => false,
            PinState::High => true,
        }
    }
}

fn print_state<T: Into<bool>>(state: T) {
    println!("{:?}", state.into());
}

fn main() {
    print_state(false);
    print_state(true);
    print_state(PinState::Low);
    print_state(PinState::High);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions