- Learning Rust
- Paul Johnson Vesa Kaihlavirta
- 119字
- 2021-07-02 23:07:20
The difference between println! and println
Up to this point, we've used println! for outputting text. This is fine, but consider what println! does. Whenever you see a ! mark, it symbolizes a macro. Macros are used when some part of the function needs to be executed at compile time, rather than at runtime.
Consider the following:
println!("{}", a); Console.WriteLine("{0}", a);
In C#, the preceding snippet will output a line with the value of a on the line. In this case, a can be of any type that supports conversion to a formatted output. The same applies to Rust. A line is output with the value of a.
The println! macro is actually implemented in the Rust standard library.
推薦閱讀
- Data Visualization with D3 4.x Cookbook(Second Edition)
- 從零構建知識圖譜:技術、方法與案例
- C#程序設計實訓指導書
- CentOS 7 Server Deployment Cookbook
- Learn Scala Programming
- PHP網絡編程學習筆記
- Securing WebLogic Server 12c
- Swift 4 Protocol-Oriented Programming(Third Edition)
- Test-Driven JavaScript Development
- Rust游戲開發實戰
- GameMaker Essentials
- Distributed Computing in Java 9
- Python數據可視化之美:專業圖表繪制指南(全彩)
- Python機器學習與量化投資
- MATLAB 2020 GUI程序設計從入門到精通