Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Array

Uma sequência de elementos de tamanho fixo onde todos os itens devem ser do mesmo tipo de dado.

#![allow(unused)]
fn main() {
let lista = ["Batata", "Cebola", "Alho", "Cenoura"];
println!("{:?}", lista);
}
#![allow(unused)]
fn main() {
let lista: [f32; 4] = [0.2, 0.4, 0.6, 0.8];
println!("{:?}", lista);
}
#![allow(unused)]
fn main() {
let lista: [&str; 4];
lista = ["Canadá", "Japão", "Brasil", "Egito"];
println!("{:?}", lista);
}
#![allow(unused)]
fn main() {
let [a, b, c]: [char; 3] = ['1', '2', '3'];
let lista = [a, b, c];
println!("{:?}", lista);
}
#![allow(unused)]
fn main() {
let lista: [String; 3] = [String::from("A1"), String::from("B2"), String::from("C3")];
let [a, b, c] = lista;
println!("{:?}, {:?}, {:?}", a, b, c);
}