extensible

Crates.ioextensible
lib.rsextensible
version0.0.1
sourcesrc
created_at2015-05-10 03:02:50.185642
updated_at2015-12-11 23:58:51.47213
descriptionA plugin to prevent exhaustive matches from being used on enums marked as 'extensible'
homepage
repositoryhttps://github.com/Manishearth/rust-extensible
max_upload_size
id2069
size5,082
Manish Goregaokar (Manishearth)

documentation

README

rust-extensible

Extensible enums for Rust

This is a plugin form of this RfC.

Basically, if an enum is marked #[extensible], this plugin will prevent its use in a match statement lacking a wildcard. This lets library authors define stable enums whilst keeping the flexibility of extending them later.

#[extensible]
enum Foo {
    Bar,
    Baz(u8),
    Quux
}
pub use Foo::*;

fn main() {
    let x = Bar;
    let mut out = match x {
        Bar => 1u8,
        Baz(y) => y,
        Quux => 0u8, 
        // There is no wildcard here, so it will not compile
    };
    println!("{}", out);

    // This is fine
    out = match x {
        Bar => 1u8,
        Baz(y) => y,
        _ => 0u8, // THis will compile fine
    };
    println!("{}", out);
}
Commit count: 7

cargo fmt