module-concept

Rust Visibility of enum variants

Unlike fields of a public struct, variants of a public enum are public. The enum and its access path must still be reachable. This makes an enum useful for describing a finite set of public outcomes. Expected result (not executed): true Why: The caller constructs a public variant through job::Status. Common mistake: Trying to write pub on individual enum variants.

Formal Syntax & Structure

rust syntaxrust
pub enum Status { Ready, Waiting }

Working Example

Example Snippetrust
mod job { pub enum Status { Ready, Waiting } }fn main() {    let state = job::Status::Ready;    println!("{}", matches!(state, job::Status::Ready));}
Rust Reference