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

Fmt Functions

Formatting functions และ utilities

use std::fmt;
fn main() {
// format_args! creates fmt::Arguments (zero allocation)
let args = format_args!("Hello, {}!", "world");
println!("{}", args);
// Used internally by format!, print!, etc.
// Passing to functions
fn log(args: fmt::Arguments) {
println!("[LOG] {}", args);
}
log(format_args!("User {} logged in", "Alice"));
log(format_args!("Value: {}", 42));
// With formatting options
log(format_args!("Float: {:.2}", 3.14159));
log(format_args!("Padded: {:>10}", "test"));
// Multiple arguments
let x = 1;
let y = 2;
log(format_args!("{} + {} = {}", x, y, x + y));
}

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

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