Enum and Constant of Rust

Enum and Constant of Rust

⚡ use - defined to import some or all enum defined and used them directly.

⚡ const - keyword that allowed you to define an unchangeable value.

main.rs

#[derive(Debug)]
enum Rustlearning{
    HOME,
    STUDENT,
}

fn main(){

    use crate::Rustlearning::*;
    
    let status = HOME;
    println!("{:#?}", status);

}

Example of const

constant.rs

static YEAR: i32 = 2022;
const WELCOME: &str = "Welcoming Year";

fn main(){
    
    println!("Happy New Year {}", YEAR);
    println!("{} {}", WELCOME, YEAR);
 
}

Github: https://github.com/eshaikhahmed/rust_learnings

 

Ejaz Shaikh

I'm passionate about freelancing, technology and healthy lifestyle. I enjoy writing code and writing about code.

Something awesome will come here..