bases2

src/main.rs

/// Rust basics:
///     - Functions
///     - Arguments are "moved"
///     - if is an expression
///     - for loops revisited

const SIZE: usize = 9;

fn read_command_line() -> [i32; SIZE] {
    [10, 32, 12, 43, 52, 53, 83, 2, 9]
}

// Check if the size is large enough (more that 1 element)
fn check_size(size: usize) {
    if size == 0 {
        panic!("Size is of tab = 0.");
    }
}

// Prints tab and returns tab.
// Tab would be destructed at the end of the function otherwise.
fn print_tab(tab: [i32; SIZE]) {
    for t in tab {
        print!("{} ", t);
    }
    println!();
}

fn min_i32(lhs: i32, rhs: i32) -> i32 {
    if lhs < rhs { lhs } else { rhs }
}

fn find_min(tab: [i32; SIZE]) -> i32 {
    check_size(SIZE);
    let mut min = i32::MAX;
    for t in tab {
        min = min_i32(min, t);
    }
    min
}

fn main() {
    let tab = read_command_line();
    println!("Among the numbers in the list:");
    print_tab(tab);
    let min = find_min(tab);
    println!("The minimal value is: {}", min);
}