Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Gul Banana
Nov 28, 2003

VikingofRock posted:

To be fair, macros much better in Rust than they are in languages like C++. IMO Rust macros are sort of like C++ templates, in that they are often ugly internally but allow for seemingly magic functions that "just do" whatever a user wants them to do.


You could do something like

Rust code:
fn main() {
    use std::io::Write;
    std::io::stdout().write("Hello, world!".as_bytes()).unwrap();
}
if you wanted, but IMO the macro version is simpler, easier to understand, and more idiomatic, so it makes sense that they would put it in the "Hello, world!" example.

Why do you need the unwrap() at the end?

Adbot
ADBOT LOVES YOU

Gul Banana
Nov 28, 2003

Ah, that attribute is a bit like Go's required-use returns then.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply