primitive-type

Rust u8: 8-bit unsigned integer

`u8` stores nonnegative whole numbers in 8 bits. Its range is 0 through 255. A channel intensity or a single byte. Expected output: 200 Why: The chosen value is representable by u8. Common mistake: It cannot represent negative values or 256.

Formal Syntax & Structure

rust syntaxrust
let name: u8 = integer_literal;

Working Example

Example Snippetrust
fn main() {    let brightness: u8 = 200;    println!("{brightness}");}
Rust Reference