Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

type name `int` is undefined or not in scope

Tags:

rust

What does this mean?

error: type name `int` is undefined or not in scope

I am trying to compile this example:

fn minval(A: &[int]) -> int {
  A.iter().fold(A[0], |u,&a| {
    if a<u {a} else {u}
  })
}

fn main() {
    let A = [1i,2i,3i];
    let min = minval(A.as_slice());
    println!("{}", min);
}
like image 576
exebook Avatar asked Dec 24 '22 05:12

exebook


1 Answers

There is no int type in Rust. Rust has the following integer types:

  • i8, i16, i32, i64, i128: signed integer with 8/16/32/64/128 bits
  • u8, u16, u32, u64, u128: unsigned integer with 8/16/32/64/128 bits
  • isize, usize: signed/unsigned integer with pointer size (64 bit on 64 bit systems)

You can learn more about this in this chapter of the Rust book.

like image 188
Lukas Kalbertodt Avatar answered Dec 31 '22 00:12

Lukas Kalbertodt