当前位置: 首页 > 工具软件 > cargo-edit > 使用案例 >

rust中使用cargo expand查看被宏隐藏的代码

纪辰沛
2023-12-01

一、cargo expand简介

  • cargo expand目前这个需要安装nightly的toolchain,rustup toolchain install nightly-x86_64-unknown-linux-gnu

  • 安装命令:cargo +nightly install cargo-expand

使用方法:

use std::result::Result;

#[async_std::main]
async fn main() -> Result<(), std::io::Error>{
    println!("Hello, world!");
    Ok(())
}

运行cargo expand:

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
use std::result::Result;
fn main() -> Result<(), std::io::Error> {
    async fn main() -> Result<(), std::io::Error> {
        {
            {
                ::std::io::_print(::core::fmt::Arguments::new_v1(
                    &["Hello, world!\n"],
                    &match () {
                        () => [],
                    },
                ));
            };
            Ok(())
        }
    }
    async_std::task::block_on(async { main().await })
}

二、rust cargo 一些方便的三方cargo 子命令扩展

  • cargo-check - This is a wrapper around cargo rustc – -Zno-trans. It can be helpful for running a faster compile if you only need correctness checks.
    说明:代码快速编译,写代码过程中快速检查语法(常用)命令: cargo check

  • clippy - Lint your project using Clippy.
    说明:检查代码规范,并给出优化方案(常用)命令: cargo clippy

  • cargo-expand - Print the result of macro expansion and #[derive]
    expansion.
    说明:#[derive]属性宏展开打印(常用)

  • rustfmt - Format Rust code according to style guidelines.
    说明:格式化rust代码(常用)

  • cargo-watch - Watch your repo for changes and build automatically.
    说明:热布署web开发中常用

  • cargo-edit - A utility for adding (cargo-add), removing (cargo-rm), and upgrading (cargo-upgrade) cargo dependencies from the command line.
    说明:cargo-edit 是cargo子命令cargo install cargo-edit 进行安装;cargo add 通过命令添另库依赖例:cargo add async_once 删除cargo rm 更新cargo upgrade

其他列表:

  • cargo-audit - Audit Cargo.lock for crates with security vulnerabilities
  • cargo-asm, cargo-llvm-ir - Shows generates assembly or LLVM IR of Rust code
  • cargo-benchcmp - Compare output of cargo bench output, both runs over time and same benchmarks in multiple modules (e.g. for comparing multiple implementations)
  • cargo-bitbake - Generate Yocto’s bitbake recipes from your Cargo.toml
  • cargo-bloat - Find out what takes most of the space in your executable.
  • cargo-cache - Helps you manage the cargo cache (~/.cargo), print sizes and clear directories
  • cargo-check - This is a wrapper around cargo rustc -- -Zno-trans. It can be helpful for running a faster compile if you only need correctness checks.
  • cargo-cook - Cooks your crate (packaging & deploying).
  • clippy - Lint your project using Clippy.
  • cargo-cln - Alternative to cargo-clean, allows running arbitrary commands in addition to wiping out target/ directory.
  • cargo-clone - Fetch source code of a crate
  • cargo-config - Print info about the current crate.
  • cargo-count - counts lines of code in cargo projects, including giving naive unsafe statistics
  • cargo-deadlinks - Check your cargo doc documentation for broken links
  • cargo-deb - Generates & builds Debian packages from cargo projects.
  • cargo-deny - Lint your dependencies
  • cargo-deps - Create dependency diagrams for your Rust projects.
  • cargo-diet - Make your crate lean by computing size-optimal include directives for Cargo manifests.
  • cargo-do - Run multiple cargo subcommands in sequence (e.g., cargo do clean, build)
  • dors - Task runner for cargo. Deploy, load, or run other scripts from your cargo project
  • cargo-edit - A utility for adding (cargo-add), removing (cargo-rm), and upgrading (cargo-upgrade) cargo dependencies from the command line.
  • cargo-expand - Print the result of macro expansion and #[derive] expansion.
  • rustfmt - Format Rust code according to style guidelines.
  • cargo-fuzz - Command-line wrapper for using libFuzzer
  • cargo-generate - Create a new Rust project by leveraging a pre-existing git repository as a template.
  • cargo-grammarly - Use the grammarly service for checking English grammar in your crate’s documentation.
  • cargo-graph - Build GraphViz DOT files of dependency graphs. Unmaintained, consider using cargo-deps.
  • cargo-info - Get crate information and details from crates.io
  • cargo-license - List licensing info for the project’s dependencies.
  • cargo-linked - List Linked packages for a rust binary.
  • cargo-lipo - Automatically create universal libraries for iOS.
  • cargo-lock - List packages, show dependency trees, and translate formats for Cargo.lock files.
  • cargo-make - Rust task runner and build tool.
  • cargo-modules - List a project’s modules in a tree-like format.
  • cargo-multi - Run a cargo command on multiple crates.
  • cargo-open - Quickly open your crate in your editor.
  • cargo-outdated - A cargo subcommand for displaying when Rust dependencies are out of date
  • cargo-patch - Cargo Subcommand for patching dependencies using patch files.
  • cargo-pkgbuild - Generate an Arch PKGBUILD for your crate.
  • cargo-profiler - A cargo subcommand to profile your applications.
  • cargo-release - Standardizes the release process of a cargo project.
  • cargo-repro - Build and verify byte-for-byte reproducible Rust packages using a Cargo-based workflow (WIP).
  • cargo-rpm - Build RPM releases of Rust projects using cargo.
  • cargo-sandbox - Perform Cargo builds inside of a sandboxed environment (WIP).
  • cargo-script - designed to let people quickly and easily run Rust “scripts” which can make use of Cargo’s package ecosystem.
  • cargo-sort-ck - Checks that your Cargo.toml dependencies are sorted alphabetically.
  • cargo-tarpaulin - Code coverage tool for your Rust projects
  • cargo-tomlfmt - Formatting Cargo.toml
  • cargo-tree - List a project’s dependencies in a tree-like format. Also supports an “inverted” mode to help determine why a specific crate is being pulled in.
  • cargo-update - Check for cargo installed executables’ newer versions and update as needed.
  • cargo-urlcrate - Adds URLs of installing/downloading crates to Cargo output
  • cargo-valgrind - Runs a binary, example, bench, … inside valgrind to check for memory leaks. Helpful in FFI contexts.
  • cargo-vendor - Vendors all crates.io dependencies into a local directory using Cargo’s support for source replacement
  • cargo-watch - Watch your repo for changes and build automatically.
  • cargo-with - A cargo-subcommand making it easy to run the build artifacts produced by cargo run or cargo build through other tools such as gdb, strace, valgrind, rr, etc.
  • cargo-wix - Builds a Windows installer (msi) using the Wix Toolset based on the contents of a package’s manifest (Cargo.toml)
  • cargo-x - A very simple third-party cargo subcommand to execute a custom command.

参考:
cargo expand用于查看被宏隐藏的代码
rust cargo 常用命令
https://github.com/rust-lang/cargo/wiki/Third-party-cargo-subcommands

 类似资料: