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

println!

Đây là một trong những macro được dùng nhiều nhất trong Rust. Giúp in nội dung ra standard output, với một dấu newline xuống dòng.

println! có cùng cú pháp với format!.

Ví dụ:

println!(); // prints just a newline
println!("hello there!");
println!("format {} arguments", "some");

In một Struct

#[derive(Debug)]
struct MyStruct {
  item: String,
  n: i32,
}

let my_struct = MyStruct {
  item: "duyet".to_string(),
  n: 99,
};

println!("my struct = {:?}", my_struct); // my struct = MyStruct { item: "duyet", n: 99 }