如何打印由Construct_runtime在运行时生成的代码?

问题描述

我克隆了底物库。在bin/node-template/runtime/src/lib.rs中,调用construct_runtime!创建运行时。我在construct_runtime中找到了frame/support/procedural/src/construct_runtime/mod.rs的定义。它会调用construct_runtime_parsed,从而在运行时构建代码块。

let res = quote!(
        #scrate_decl

        #[derive(Clone,copy,PartialEq,Eq,#scrate::sp_runtime::RuntimeDebug)]
        pub struct #name;
        impl #scrate::sp_runtime::traits::GetNodeBlockType for #name {
            type NodeBlock = #node_block;
        }
        impl #scrate::sp_runtime::traits::GetRuntimeBlockType for #name {
            type RuntimeBlock = #block;
        }

        #outer_event

        #outer_origin

        #all_modules

        #module_to_index

        #dispatch

        #Metadata

        #outer_config

        #inherent

        #validate_unsigned

        #integrity_test
    );

我有什么方法可以打印或检查由quote!构建的传递给construct_runtime_parsed代码

解决方法

您可以将cargo expand指向runtime/src/lib.rs文件,它将输出扩展的源代码。