GithubHelp home page GithubHelp logo

Comments (4)

babybabycloud avatar babybabycloud commented on July 17, 2024

Maybe I have the same question, I didn't find a better solution to replace the below code

match key_event.code {
KeyCode::Char('A') => some_funtion('A'),
KeyCode::Char('B') => some_funtion('B'),
KeyCode::Char('C') => some_funtion('C'),
KeyCode::Char('D') => some_funtion('D'),
KeyCode::Char('E') => some_funtion('E'),
_ => (),
}

Although they all have the same logic, but I need to do the same thing for they all

from crossterm.

TimonPost avatar TimonPost commented on July 17, 2024

you can match on variable no?

enum KeyCode{
    Char(char)
}
fn some_funtion(a: char) {
    
}

fn main() {
   match KeyCode::Char('b') {
    KeyCode::Char(c) => some_funtion(c),
    _ => (),
    }
}

from crossterm.

TimonPost avatar TimonPost commented on July 17, 2024

For the macros i am not sure. Surely it removes redundancy, but the thing is that they are quite hard to understand on how to use them.

from crossterm.

babybabycloud avatar babybabycloud commented on July 17, 2024

you can match on variable no?

enum KeyCode{
    Char(char)
}
fn some_funtion(a: char) {
    
}

fn main() {
   match KeyCode::Char('b') {
    KeyCode::Char(c) => some_funtion(c),
    _ => (),
    }
}

Yes, I think this is correct. After comment on this issue, I found such usage in other project. LOL

from crossterm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.