본문 바로가기
Rust

[Rust] Rust Programming 9일차

by 꾸압 2022. 12. 16.

 

<과정>

  - 구조체의 Tuple 인덱스

[예제_1]

fn main() {
    let rect1 = (50, 30);

    println!(
        "The area of the rectangle is {} square pixels.",
        area(rect1)
    );
}

fn area(dimensions: (u32, u32)) -> u32 {
    dimensions.0 * dimensions.1
}

 

[예제_2]

struct Rectangle {
    length: u32,
    width:u32,
}

fn main() {
    let rect1 = Rectangle { length: 50, width: 30 };

    println!(
        "The area of the rectangle is {} square pixels.",
        area(&rect1)
    );
}

fn area(rectangle: &Rectangle) -> u32 {
    rectangle.length * rectangle.width
}

 

  - println!() 과 구현체(display)에 대하

 

'Rust' 카테고리의 다른 글

[Rust] Rust Programming 11일차  (0) 2022.12.18
[Rust] Rust Programming 10일차  (0) 2022.12.17
[Rust] Rust Programming 8일차  (0) 2022.12.15
[Rust] Rust Programming 7일차  (0) 2022.12.14

댓글