3 ms·
I’ll admit, the fact that Hello World requires a macro, dissuaded me from learning Rust for years.
by dqpb 4y ago
I’ll admit, the fact that Hello World requires a macro, dissuaded me from learning Rust for years.
- Cyberdog 4y agoYou’re using the past tense. Did your mind change?
- WaffleIronMaker 4y agoTechnically, you don't need a macro at all: use std::io::Write; fn main() { std::io::stdout().write(b"Hello, world!\n").unwrap(); } The reason people often use println! is that println! is variadic and can support any number of arguments to format in the string. For example: println!("x is: {}", x); This also has the benefit of allowing type checking at compile time, as opposed to using a function like printf in C, which does not have such power. Additionally, this allows Rust to take references to the variables entered without the programmer's specification, in order to prevent unnecessary copying. These reasons tie directly into Rust's philosophy of making it easy to write reliable, performant code.