1. 37
    Rustlings macros4: Using rustfmt to fix common syntax issues
    49s

Rustlings macros4: Using rustfmt to fix common syntax issues

Chris Biscardi
InstructorChris Biscardi
Share this video with your friends

Social Share Links

Send Tweet

README for this exercise.

Chris Biscardi: [0:00] In macros4, we define a macro using the macro_rules! Macro that has two implementations. One is a function that doesn't take any arguments, and one is a function that takes an expression. In both cases, we use the println! Macro to print out the value.

[0:14] In our main() function, we have my_macro called with no arguments followed by my_macro called with (7777). The Rust compiler tells us that no rules expected the token '('. In this case, all I'm going to do is insert a space and save. Note that our tests are now passing. This is because the semi colons were inserted for me by rustfmt.

[0:36] Rustfmt is a tool for formatting Rust code similar to Prettier in the JavaScript ecosystem or gofmt. It's an incredibly useful tool, as we just saw in this module, and you can set it up to be run in your editor.