Skip to content

Instantly share code, notes, and snippets.

@preveen-stack
Last active May 6, 2023 11:48
Show Gist options
  • Save preveen-stack/6541bd44db8619ea34c1289ba94953a5 to your computer and use it in GitHub Desktop.
Save preveen-stack/6541bd44db8619ea34c1289ba94953a5 to your computer and use it in GitHub Desktop.
macro expansion in rust

In rust the in order to see the expansion of the macros like println! we can use the rust-expand crate

First install the crate

cargo install cargo-expand

then use cargo expand command

for eg: a hello world in rust will look like this

fn main() {
    println!("Hello, world!");
}

with cargo expand it will look like

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2018::*;
#[macro_use]
extern crate std;
fn main() {
    {
        ::std::io::_print(::core::fmt::Arguments::new_v1(&["Hello, world!\n"], &[]));
    };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment