How to define unsupported enum value like invalid_atomic_ordering

⚓ rust    📅 2025-05-29    👤 surdeus    👁️ 4      

surdeus

I got an error atomic loads cannot have "Release" or "AcqRel" ordering in the code below:

use std::sync::atomic::{AtomicUsize, Ordering};

fn main() {
    let counter = AtomicUsize::new(0);
    println!("Result: {}", counter.load(Ordering::AcqRel));
}

I wonder if it's possible apply this on a custom Enum?

enum E1 {
    A1,
    A2,
    A3,
}

// How to let compiler report error when pass constant value E1::A3?
fn some_function(v: E1) {
    if let E1::A3 = v{
        panic!("A3 not supported")
    }
    // do something
}

3 posts - 3 participants

Read full topic

🏷️ rust_feed