Structure in Rust

Structure in Rust

Today,

Rust syntax felt a bit hard and complicated to other languages.

But after multiple iteration, it all makes sense.

main.rs

//We need to display or print whole structure , that's why debug
#[derive(Debug)]
struct Point{
    x: f32,
    y: f32,
}

// duplicate structure name is not allowed
#[derive(Debug)]
struct Point2(i32, f32);

fn main(){

    let first_point = Point{x: 2.3, y: 4.5};
    println!("{:?}", first_point);
    
    let second_point = Point2(2,1.4);
    println!("{:?}", second_point);
}


Note: Slices are just a references, it is slice of an array. Slices values change or modify result into an error

Wow I totally enjoyed todays learning, it was totally new. Feel free to join me and we can have fun together.

 

Ejaz Shaikh

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

Something awesome will come here..