How to import and reference enumeration types in Rust?

How do you import and reference enum types from Rust std lib?

I am trying to use the Ordering enum from the std::sync::atomics . My attempts so far have failed:

 use std::sync::atomics::AtomicBool; use std::sync::atomics::Ordering; // error unresolved import: there is no `Relaxed` in `std::sync::atomics::Ordering` // use std::sync::atomics::Ordering::Relaxed; fn main() { let mut ab = AtomicBool::new(false); let val1 = ab.load(Ordering::Relaxed); // error: unresolved import: // there is no `Relaxed` in `std::sync::atomics::Ordering` println!("{:?}", val1); ab.store(true, Ordering.Relaxed); // error: unresolved name `Ordering` let val2 = ab.load(Ordering(Relaxed)); // error: unresolved name `Relaxed` println!("{:?}", val2); } 

I am currently using Rust v. 0.9.

+9
rust
source share
2 answers

Editor's Note: This answer precedes Rust 1.0 and is not applicable to Rust 1.0.

Variants of enum are not limited within enum; thus they are std::sync::atomics::Relaxed etc.

The enum options listed are subject to issue 10090 .

+8
source share

Starting with Rust 1.0, enum variants are limited to the enum type. You can use directly d:

 pub use self::Foo::{A, B}; pub enum Foo { A, B, } fn main() { let a = A; } 

or you can use a name indicating the type:

 pub enum Foo { A, B, } fn main() { let a = Foo::A; } 
+7
source share

All Articles