### Install an example from a crate Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/man/cargo-install.md Installs the 'my-example' example from 'my-crate'. ```bash cargo install my-crate --example my-example ``` -------------------------------- ### Example 2 Source: https://github.com/rust-lang/cargo.git/blob/master/crates/mdman/tests/compare/expected/options.md Another example of using my-command. ```bash my-command --xyz ``` -------------------------------- ### Example 1 Source: https://github.com/rust-lang/cargo.git/blob/master/crates/mdman/tests/compare/expected/options.md A basic example of using my-command. ```bash my-command --abc ``` -------------------------------- ### Install or reinstall the package in the current directory Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/man/cargo-install.md This example demonstrates installing or reinstalling the package located in the current directory. ```bash cargo install --path . ``` -------------------------------- ### Install or upgrade a package from crates.io Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/man/cargo-install.md This example shows how to install or upgrade the 'ripgrep' package from crates.io. ```bash cargo install ripgrep ``` -------------------------------- ### Install command synopsis Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/man/generated_txt/cargo-install.txt Shows the different ways to use the cargo install command. ```bash cargo install [options] crate[@version]… cargo install [options] --path path cargo install [options] --git url [crate…] cargo install [options] --list ``` -------------------------------- ### Install mdBook Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/contrib/src/documentation/index.md Installs the mdBook tool, which is required for building the Cargo Book. ```console $ cargo install mdbook ``` -------------------------------- ### build.target example Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/reference/config.md Example of specifying multiple target platforms in the build configuration. ```toml [build] target = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"] ``` -------------------------------- ### Install a crate from a local path Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/man/cargo-install.md Installs a crate from a local directory. ```bash cargo install --path /path/to/my-crate ``` -------------------------------- ### Installing nightly components Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/contrib/src/tests/running.md Command to install necessary components for nightly tests. ```bash rustup component add rustc-dev llvm-tools-preview --toolchain=nightly ``` -------------------------------- ### Profile Configuration Example Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/reference/config.md Example of how to modify profile settings via configuration. ```toml [profile.] inherits = "dev" opt-level = 0 debug = true split-debuginfo = '...' strip = "none" debug-assertions = true overflow-checks = true lto = false panic = 'unwind' incremental = true codegen-units = 16 rpath = false ``` -------------------------------- ### Get help for a command Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/man/cargo-help.md Example of how to get help for a specific Cargo command. ```bash cargo help build ``` -------------------------------- ### Usage Examples Source: https://github.com/rust-lang/cargo.git/blob/master/crates/mdman/tests/compare/expected/options.txt Provides concrete examples of how to use the my-command utility. ```bash my-command --abc ``` ```bash my-command --xyz ``` -------------------------------- ### Get help for a nested command Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/man/cargo-help.md Example of how to get help for a nested Cargo command. ```bash cargo help report future-incompatibilities ``` -------------------------------- ### Create a new package Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/getting-started/first-steps.md Use `cargo new` to start a new package. By default, it creates a binary program. ```console $ cargo new hello_world ``` -------------------------------- ### Compile the project Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/getting-started/first-steps.md Compile the project using `cargo build`. ```console $ cargo build Compiling hello_world v0.1.0 (file:///path/to/package/hello_world) ``` -------------------------------- ### Get Build Rustflags Configuration Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/reference/unstable.md Example of using `cargo config get` to retrieve a specific configuration value. ```bash cargo +nightly -Zunstable-options config get build.rustflags ``` -------------------------------- ### Example with subcommands Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/commands/cargo-help.md This example demonstrates how to get help for a command with subcommands, showing both space-separated and dash-joined formats. ```bash cargo help report future-incompatibilities ``` ```bash cargo help report-future-incompatibilities ``` -------------------------------- ### Command Option Examples Source: https://github.com/rust-lang/cargo.git/blob/master/crates/mdman/tests/compare/expected/options.txt Demonstrates the usage of various command-line options for my-command. ```bash my-command --foo-bar my-command -p spec my-command --complex my-command @filename my-command --foo [bar] my-command --foo[=bar] my-command --split-block ``` -------------------------------- ### Run an example with extra arguments Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/man/cargo-run.md Builds and runs a specific example, passing additional arguments to it. ```bash cargo run --example exname -- --exoption exarg1 exarg2 ``` -------------------------------- ### Section Timings Example Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/reference/unstable.md Example of using the `-Zsection-timings` flag with `cargo build --timings` to get detailed compilation section timings. ```console cargo +nightly -Zsection-timings build --timings ``` -------------------------------- ### Build and open the book Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/contrib/src/documentation/index.md Builds the Cargo Book and opens it in a web browser. ```console $ mdbook build --open ``` -------------------------------- ### Output from build script Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/reference/build-script-examples.md This text output shows an example of what Cargo might print when running `cargo build -vv` on a system with libz installed, indicating successful linking. ```text [libz-sys 0.1.0] cargo::rustc-link-search=native=/usr/lib [libz-sys 0.1.0] cargo::rustc-link-lib=z [libz-sys 0.1.0] cargo::rerun-if-changed=build.rs ``` -------------------------------- ### Uninstall a previously installed package Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/man/cargo-uninstall.md Example of how to uninstall a package. ```bash cargo uninstall ripgrep ``` -------------------------------- ### Run the compiled program Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/getting-started/first-steps.md Run the compiled binary located in the `target/debug/` directory. ```console $ ./target/debug/hello_world Hello, world! ``` -------------------------------- ### Verbose output option Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/man/generated_txt/cargo-report.txt Example of using the verbose flag to get more detailed output, including how it relates to configuration values. ```bash -v, --verbose Use verbose output. May be specified twice for “very verbose” output which includes extra output such as dependency warnings and build script output. May also be specified with the term.verbose config value . ``` -------------------------------- ### Successful Rust installation message Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/getting-started/installation.md This message indicates that Rust has been successfully installed. ```text Rust is installed now. Great! ``` -------------------------------- ### Synopsis Examples Source: https://github.com/rust-lang/cargo.git/blob/master/crates/mdman/tests/compare/expected/options.txt Illustrates different ways to invoke the my-command utility based on its synopsis. ```bash my-command [--abc | --xyz] name my-command [-f file] my-command (-m | -M) [oldbranch] newbranch my-command (-d | -D) [-r] branchname… ``` -------------------------------- ### Build Script Example Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/reference/build-script-examples.md An example build script that generates a Rust file. ```rust // build.rs use std::env; use std::fs; use std::path::Path; fn main() { let out_dir = env::var_os("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir).join("hello.rs"); fs::write( &dest_path, "pub fn message() -> &'static str { \"Hello, World!\" } " ).unwrap(); println!("cargo::rerun-if-changed=build.rs"); } ``` -------------------------------- ### Running the example Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/guide/dependencies.md Example output of 'cargo run' after implementing the Rust code. ```console $ cargo run Running `target/hello_world` Did our date match? true ``` -------------------------------- ### Badges Section Example Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/reference/manifest.md Example of the `[badges]` section for specifying status badges, with a `maintenance` table example. ```toml [badges] # The `maintenance` table indicates the status of the maintenance of # the crate. This may be used by a registry, but is currently not # used by crates.io. See https://github.com/rust-lang/crates.io/issues/2437 # and https://github.com/rust-lang/crates.io/issues/2438 for more details. # # The `status` field is required. Available options are: # - `actively-developed`: New features are being added and bugs are being fixed. # - `passively-maintained`: There are no plans for new features, but the maintainer intends to # respond to issues that get filed. # - `as-is`: The crate is feature complete, the maintainer does not intend to continue working on # it or providing support, but it works for the purposes it was designed for. # - `experimental`: The author wants to share it with the community but is not intending to meet # anyone's particular use case. # - `looking-for-maintainer`: The current maintainer would like to transfer the crate to someone # else. ``` -------------------------------- ### src/main.rs file Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/getting-started/first-steps.md The default `src/main.rs` file contains a simple "hello world" program. ```rust fn main() { println!("Hello, world!"); } ``` -------------------------------- ### Scraping examples configuration in Cargo.toml Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/reference/unstable.md Configuration in Cargo.toml to enable or disable scraping examples from library and example targets. ```toml # Enable scraping examples from a library [lib] doc-scrape-examples = true # Disable scraping examples from an example target [[example]] name = "my-example" doc-scrape-examples = false ``` -------------------------------- ### Serve the book Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/contrib/src/documentation/index.md Launches a local web server for the Cargo Book, with automatic rebuilding and browser reloading on file changes. ```console $ mdbook serve ``` -------------------------------- ### Install Rust and Cargo using rustup (Linux/macOS) Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/getting-started/installation.md This command downloads and executes the rustup installation script for Linux and macOS systems. ```bash curl https://sh.rustup.rs -sSf | sh ``` -------------------------------- ### Relative path examples Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/reference/config.md Provides examples of how relative paths are resolved for different configuration settings. ```toml # Relative path examples. [target.x86_64-unknown-linux-gnu] runner = "foo" # Searches `PATH` for `foo`. [source.vendored-sources] # Directory is relative to the parent where `.cargo/config.toml` is located. # For example, `/my/project/.cargo/config.toml` would result in `/my/project/vendor`. directory = "vendor" ``` -------------------------------- ### List installed binaries Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/man/cargo-install.md Lists all installed binary crates. ```bash cargo install --list ``` -------------------------------- ### Target Configuration Examples Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/reference/config.md Examples of configuring settings for specific platform targets using platform triples and cfg expressions. ```toml [target.thumbv7m-none-eabi] linker = "arm-none-eabi-gcc" runner = "my-emulator" rustflags = ["…", "…"] [target.'cfg(all(target_arch = "arm", target_os = "none"))'] runner = "my-arm-wrapper" rustflags = ["…", "…"] ``` -------------------------------- ### TOML include examples Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/reference/config.md Illustrates different ways to include external TOML configuration files. ```toml # array of paths include = [ "frodo.toml", "samwise.toml", ] # inline tables for more control include = [ { path = "required.toml" }, { path = "optional.toml", optional = true }, ] ``` -------------------------------- ### Build the book Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/contrib/src/documentation/index.md Builds the Cargo Book using mdBook. ```console $ mdbook build ``` -------------------------------- ### Install sccache Source: https://github.com/rust-lang/cargo.git/blob/master/src/doc/src/reference/build-cache.md Command to install sccache. ```bash cargo install sccache ```