Skip to content

Latest commit

 

History

History
53 lines (37 loc) · 724 Bytes

File metadata and controls

53 lines (37 loc) · 724 Bytes

Generic type

Example

Execute the following command to run ./solutions/examples/generic.rs

cargo run --example generic

Exercises

Exercises are in ./exercises/src/lib.rs

Exercise 1

pub fn first(t: (u32, i32)) -> u32 {
    t.0
}

Turn this function into a generic function.

Exercise 2

pub fn last(t: (u32, i32)) -> i32 {
    t.1
}

Turn this function into a generic function.

Exercise 3

#[derive(Debug)]
pub struct Rectangle {
    pub top: u32,
    pub left: u32,
    pub width: u32,
    pub height: u32,
}

Turn this struct into a generic struct.

Test

cargo test