easy_switch

Crates.ioeasy_switch
lib.rseasy_switch
version0.2.0
sourcesrc
created_at2023-03-24 15:38:50.060596
updated_at2023-03-27 14:19:47.784942
descriptionA macro for traditional C-style switch statements
homepagehttps://github.com/dzfrias/easy_switch
repositoryhttps://github.com/dzfrias/easy_switch
max_upload_size
id819381
size9,418
Diego Frias (dzfrias)

documentation

https://docs.rs/easy_switch

README

easy_switch

Build status Crates.io Docs Status

A macro to emulate switch statements in C-style languages. Get rid of those long if/else if chains!

Syntax

Use the switch! macro to get started! This will look like a match expression, but of course does no actual pattern matching.

use easy_switch::switch;

#[derive(PartialEq, Eq)]
struct Example {
    field: i32,
    field2: i32,
}

impl Example {
    pub fn new(field2: i32) -> Self {
        Self {
            field: 10,
            field2,
        }
    }
}

let switchable = Example::new(10);
let result = switch! { switchable;
    Example::new(50), 50 == 50 => 50,
    Example::new(20), 50 == 50, 20 == 20 => 20,
    _ => 0,
};
assert_eq!(0, result);

Check out the docs for more information on this macro.

License

This crate is licensed under the MIT license.

Commit count: 15

cargo fmt