Skip to content
เข้าสู่ระบบ

Tuple Primitives

Tuple types และ operations

fn main() {
// Basic tuple
let pair = (42, "hello");
println!("Pair: {:?}", pair);
// With type annotation
let typed: (i32, f64, bool) = (10, 3.14, true);
println!("Typed: {:?}", typed);
// Single element (note trailing comma)
let single: (i32,) = (42,);
println!("Single: {:?}", single);
// Unit tuple
let unit: () = ();
println!("Unit: {:?}", unit);
// Nested tuples
let nested = ((1, 2), (3, 4));
println!("Nested: {:?}", nested);
// Large tuple (up to 12 for common traits)
let big = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
println!("Big: {:?}", big);
// Mixed types
let mixed = (42, "hello", true, 3.14, vec![1, 2, 3]);
println!("Mixed: {:?}", mixed);
}

เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม

ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด