Numeric types and casts

Use int and float for ordinary arithmetic. Width-specific forms such as u8, i32, and f32 are useful for file formats and native boundaries; bool, string, and void cover the other basic values.

moon does not mix numeric types implicitly. as Type requests an explicit scalar conversion. Arithmetic on a narrow integer keeps that width, so overflow wraps as the example shows. Later lessons introduce collection, function, optional, result, and pointer types where they are used.

fn main() {
  let near: u8 = 250 as u8
  let step: u8 = 10 as u8
  let wrapped: u8 = near + step
  println(wrapped)
}
Output & diagnostics
Expected:
4
Ctrl/⌘+Enter runs the current lesson.