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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset