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

Formatting - จัดรูปแบบข้อความ

std::fmt module มี traits และ macros สำหรับจัดรูปแบบข้อความ output ตั้งแต่ simple prints ไปจนถึง complex formatting

Rust มี 2 traits หลักสำหรับแสดงผลข้อความ:

  • Display - สำหรับ user-facing output (ใช้ {})
  • Debug - สำหรับ developer debugging (ใช้ {:?})
fn main() {
let name = "Rust";
let numbers = vec![1, 2, 3];
// Display format
println!("Hello, {}!", name);
// Debug format
println!("numbers: {:?}", numbers);
// Pretty debug
println!("numbers: {:#?}", numbers);
}

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

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