nandi/rustnimpublic Fork 0
04eb29f2f77152e460b50f58935cb88305227b43
Commits
Clone
git clone https://git.rickub.com/nandi/rustnim.git
git clone ssh://git@rickub.com/nandi/rustnim.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Add enums, Option/Result, `?`, and the machinery base16ct needs around them b0ccd80 · on 04eb29f2f77152e460b50f58935cb88305227b43 · nandithebull · 20h ago
017-enum-simple.rs · 21 lines · 534 BRust Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
// A C-like enum is a plain Nim enum: it compares and `case`-checks like Rust's.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
enum Error {
    InvalidEncoding,
    InvalidLength,
}

fn describe(e: Error) -> i32 {
    match e {
        Error::InvalidEncoding => 1,
        Error::InvalidLength => 2,
    }
}

fn main() {
    let a = Error::InvalidEncoding;
    let b = Error::InvalidLength;
    println!("{} {}", describe(a), describe(b));
    println!("{:?} {:?}", a, b);
    println!("{} {}", a == b, a == Error::InvalidEncoding);
}