### Basic Rust Clap Application Setup Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/i686-pc-windows-msvc/clap/index A minimal Rust program demonstrating the basic setup of a `clap` application. It initializes an `App` with a name and version, then processes command-line arguments, serving as a starting point for `clap` usage. ```Rust extern crate clap; use clap::App; fn main() { App::new("fake").version("v1.0-beta").get_matches(); } ``` -------------------------------- ### Setup Plotters Interactive Jupyter Notebook Source: https://docs.rs/tinyvec/latest/tinyvec/crate/plotters/0.3.7/target-redirect/x86_64-unknown-linux-gnu/plotters/index Instructions to set up and run the interactive Plotters tutorial using Jupyter Notebook and evcxr. This involves cloning the tutorial data repository and starting the Jupyter server locally. ```Bash git clone https://github.com/38/plotters-doc-data cd plotters-doc-data jupyter notebook ``` -------------------------------- ### Steps to Run Clap Pre-Built Example Source: https://docs.rs/tinyvec/latest/tinyvec/clap/2.9 These shell commands provide a quick guide to setting up and running a pre-built `clap` example. Users can clone the repository, compile the project in release mode, and then execute the compiled binary with the `--help` flag to explore its functionality. ```Bash $ git clone https://github.com/kbknapp/clap-rs && cd clap-rs/clap-tests $ cargo build --release $ ./target/release/claptests --help ``` -------------------------------- ### Clap Basic CLI: Minimal Rust Example Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/x86_64-pc-windows-msvc/clap/index A minimal Rust `main.rs` file demonstrating the basic setup of a `clap` application. This simple program will automatically generate default help and version information when run. ```Rust extern crate clap; use clap::App; fn main() { App::new("fake").version("v1.0-beta").get_matches(); } ``` -------------------------------- ### Rust Clap CLI: Minimal Application Example Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/x86_64-apple-darwin/clap/index A minimal Rust program demonstrating the basic setup of a `clap` application, defining a new app with a name and version, and parsing command-line arguments. ```Rust extern crate clap; use clap::App; fn main() { App::new("fake").version("v1.0-beta").get_matches(); } ``` -------------------------------- ### Set up Jupyter Notebook for Plotters Tutorial Source: https://docs.rs/tinyvec/latest/tinyvec/crate/plotters/0.3.7/target-redirect/x86_64-pc-windows-msvc/plotters/index Instructions to clone the plotters-doc-data repository and start Jupyter Notebook to access the interactive tutorial. This requires Jupyter and evcxr to be pre-installed. ```bash git clone https://github.com/38/plotters-doc-data cd plotters-doc-data jupyter notebook ``` -------------------------------- ### Minimal Clap Program in Rust Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/^2 A minimal Rust program demonstrating the basic setup of a `clap` application. It initializes a new `App` with a name and version, then processes command-line matches. ```Rust extern crate clap; use clap::App; fn main() { App::new("fake").version("v1.0-beta").get_matches(); } ``` -------------------------------- ### Run Clap Tests with Just Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/x86_64-pc-windows-msvc/clap/index If you have the `just` utility installed, you can use its prebuilt recipes to simplify running tests. This command executes the `run-tests` recipe. ```Bash $ just run-tests ``` -------------------------------- ### Minimal Rust Clap Application Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/i686-unknown-linux-gnu/clap/index A basic `main.rs` file demonstrating the simplest `clap` application setup. It creates an `App` with a name and version, allowing `clap` to auto-generate help and version output. ```Rust extern crate clap; use clap::App; fn main() { App::new("fake").version("v1.0-beta").get_matches(); } ``` -------------------------------- ### Install Rebar for Regex Benchmarking Source: https://docs.rs/tinyvec/latest/tinyvec/crate/regex/1.11 These commands guide the user through cloning the `rebar` repository and installing it locally using `cargo install`. `rebar` is an external tool used for comprehensive benchmarking of the `regex` crate's performance. ```Bash $ git clone https://github.com/BurntSushi/rebar $ cd rebar $ cargo install --path ./ ``` -------------------------------- ### Mockall: Getting Started with `#[automock]` Trait Mocking Source: https://docs.rs/tinyvec/latest/tinyvec/mockall/^0.13 This example demonstrates the basic usage of Mockall's `#[automock]` attribute to create a mock for a trait. It shows how to define a trait, apply `#[automock]`, instantiate the mock, set an expectation for a method call with a specific argument and call count, and define a return value based on the input. Finally, it asserts that the mocked behavior is correctly invoked by a function under test. ```Rust use mockall::*; use mockall::predicate::*; #[automock] trait MyTrait { fn foo(&self, x: u32) -> u32; } fn call_with_four(x: &dyn MyTrait) -> u32 { x.foo(4) } let mut mock = MockMyTrait::new(); mock.expect_foo() .with(predicate::eq(4)) .times(1) .returning(|x| x + 1); assert_eq!(5, call_with_four(&mock)); ``` -------------------------------- ### Run Pre-Built Clap Examples Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/^2 Instructions for cloning the `clap` repository, compiling a specific example, and running its help information or executing it with arguments. ```Shell $ git clone https://github.com/clap-rs/clap && cd clap-rs/ $ cargo build --example $ ./target/debug/examples/ --help $ cargo run --example -- [args to example] ``` -------------------------------- ### Clap Example: Clone and Run Pre-Built Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/x86_64-pc-windows-msvc/clap/index Steps to clone the `clap` repository, build a pre-built example, and run its help command to demonstrate `clap`'s functionality. This allows users to quickly try out a working example. ```Shell $ git clone https://github.com/clap-rs/clap && cd clap-rs/tests $ cargo build --release $ ./target/release/claptests --help $ Play with the arguments! ``` -------------------------------- ### Steps to Try Pre-Built Clap Example Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/i686-unknown-linux-gnu/clap/index Commands to clone the `clap` repository, navigate to the tests directory, compile a pre-built example, and run its help command to demonstrate `clap`'s functionality. ```Shell $ git clone https://github.com/clap-rs/clap && cd clap-rs/tests $ cargo build --release $ ./target/release/claptests --help ``` -------------------------------- ### Get Test List with nextest-metadata in Rust Source: https://docs.rs/tinyvec/latest/tinyvec/nextest-metadata/^0.12 This Rust example demonstrates how to use the `nextest-metadata` crate to programmatically retrieve a list of tests from a repository. It requires `cargo nextest` to be installed and uses `ListCommand` to execute the listing and obtain a `TestListSummary`. ```Rust // This example requires `cargo nextest` to be installed. use nextest_metadata::ListCommand; let command = ListCommand::new(); let test_list = command.exec().unwrap(); // The result is a TestListSummary. println!("{:?}", test_list); ``` -------------------------------- ### Setting up Multiaxis Plots in Rust Source: https://docs.rs/tinyvec/latest/tinyvec/criterion-plot/^0.4 This Rust snippet introduces the setup for a multiaxis plot using `criterion_plot`. It defines a complex transfer function `tf` and sets up the start and end range for the plot, indicating preparation for a frequency response or similar multi-axis visualization. ```Rust use std::f64::consts::PI; use itertools_num::linspace; use num_complex::Complex; use criterion_plot::prelude::*; fn tf(x: f64) -> Complex { Complex::new(0., x) / Complex::new(10., x) / Complex::new(1., x / 10_000.) } let (start, end): (f64, f64) = (1.1, 90_000.); ``` -------------------------------- ### Run Pre-Built Clap Example Commands Source: https://docs.rs/tinyvec/latest/tinyvec/clap/%7E2 Shell commands to clone the `clap` repository, compile a pre-built example, and run its help command to demonstrate `clap` functionality. ```Shell $ git clone https://github.com/clap-rs/clap && cd clap-rs/tests $ cargo build --release $ ./target/release/claptests --help ``` -------------------------------- ### Configure Compiler and Run Uiua Assembly Source: https://docs.rs/tinyvec/latest/tinyvec/uiua This example shows how to create a `Compiler` instance, configure it to print diagnostics, load a Uiua string, finish compilation to get assembly, and then execute the compiled assembly using `Uiua::run_asm()`. ```Rust use uiua::*; let mut comp = Compiler::new(); comp.print_diagnostics(true); let asm = comp.load_str("+ 3 5").unwrap().finish(); let mut uiua = Uiua::with_native_sys(); uiua.run_asm(asm).unwrap(); let res = uiua.pop_int().unwrap(); assert_eq!(res, 8); ``` -------------------------------- ### Clap Pre-Built Example Test Commands Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/i686-pc-windows-msvc/clap/index Shell commands to clone the `clap` repository, compile a pre-built example, and run it to demonstrate `clap`'s CLI argument parsing and help generation. ```Shell $ git clone https://github.com/clap-rs/clap && cd clap-rs/tests $ cargo build --release $ ./target/release/claptests --help ``` -------------------------------- ### Module: guide for serde_with User Guide Source: https://docs.rs/tinyvec/latest/tinyvec/serde_with/^1.3 Provides the user guide for the `serde_with` library, offering detailed instructions and examples. ```APIDOC Module: guide Description: `serde_with` User Guide ``` -------------------------------- ### Quick Start: Define and Run Oxanus Worker and Queue in Rust Source: https://docs.rs/tinyvec/latest/tinyvec/oxanus/latest This example demonstrates the basic setup for using Oxanus, including defining a custom worker and queue, configuring the context and storage, enqueueing a job, and running the worker to process jobs. ```Rust use oxanus::{Worker, Queue, Context, Config, Storage}; use serde::{Serialize, Deserialize}; // Define your worker #[derive(Debug, Serialize, Deserialize)] struct MyWorker { data: String, } #[async_trait::async_trait] impl Worker for MyWorker { type Context = MyContext; type Error = MyError; async fn process(&self, ctx: &Context) -> Result<(), MyError> { // Process your job here Ok(()) } } // Define your queue #[derive(Serialize)] struct MyQueue; impl Queue for MyQueue { fn to_config() -> QueueConfig { QueueConfig::as_static("my_queue") } } // Define your context struct MyContext {} // Run your worker async fn run_worker() -> Result<(), OxanusError> { let ctx = Context::value(MyContext {}); let storage = Storage::builder().from_env()?.build()?; let config = Config::new(&storage) .register_queue::() .register_worker::(); // Enqueue some jobs storage.enqueue(MyQueue, MyWorker { data: "hello".into() }).await?; // Run the worker oxanus::run(config, ctx).await?; Ok(()) } ``` -------------------------------- ### Basic Actix Web Server Example Source: https://docs.rs/tinyvec/latest/tinyvec/actix-web/^4 Demonstrates how to set up a minimal Actix Web application. It defines a GET route `/hello/{name}` that responds with a greeting and shows the main function structure to bind and run the HTTP server. ```Rust use actix_web::{get, web, App, HttpServer, Responder}; #[get("/hello/{name}")] async fn greet(name: web::Path) -> impl Responder { format!("Hello {}!", name) } #[actix_web::main] // or #[tokio::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new().service(greet) }) .bind(("127.0.0.1", 8080))? .run() .await } ``` -------------------------------- ### Example HTTP GET Request Matching Warp Filter Source: https://docs.rs/tinyvec/latest/tinyvec/warp/^0 This example shows an HTTP GET request that successfully matches the previously defined Warp filter, including the path parameter and the 'User-Agent' header. ```HTTP GET /hello/sean HTTP/1.1 Host: hyper.rs User-Agent: reqwest/v0.8.6 ``` -------------------------------- ### Multiaxis Plotting Setup in Rust Source: https://docs.rs/tinyvec/latest/tinyvec/crate/criterion-plot/0.4.5/target-redirect/x86_64-unknown-linux-gnu/criterion_plot/index This Rust snippet introduces a transfer function `tf` returning a complex number and sets up a range for plotting. It's an incomplete example showing the initial setup for a multi-axis plot using `criterion_plot`. ```rust use std::f64::consts::PI; use itertools_num::linspace; use num_complex::Complex; use criterion_plot::prelude::*; fn tf(x: f64) -> Complex { Complex::new(0., x) / Complex::new(10., x) / Complex::new(1., x / 10_000.) } let (start, end): (f64, f64) = (1.1, 90_000.); ``` -------------------------------- ### RUST_LOG Example: Target Prefix Matching Source: https://docs.rs/tinyvec/latest/tinyvec/env_logger/*/env_logger This API documentation snippet demonstrates how `RUST_LOG=example` enables logging for targets that start with 'example', including `example`, `example::test`, `example::test::module::submodule`, and `examples::and_more_examples`. It highlights the prefix-search filtering capability of `RUST_LOG`. ```APIDOC RUST_LOG=example ``` -------------------------------- ### Axum Hello World Application Source: https://docs.rs/tinyvec/latest/tinyvec/axum/^0 A basic 'Hello, World!' example demonstrating how to set up an axum application with a single route and run it using hyper on port 3000. This example requires enabling tokio's `macros` and `rt-multi-thread` features. ```Rust use axum::{ routing::get, Router, }; #[tokio::main] async fn main() { // build our application with a single route let app = Router::new().route("/", get(|| async { "Hello, World!" })); // run our app with hyper, listening globally on port 3000 let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); axum::serve(listener, app).await.unwrap(); } ``` -------------------------------- ### Quick Start: Defining and Running an Oxanus Worker Source: https://docs.rs/tinyvec/latest/tinyvec/crate/oxanus/0.3.5/target-redirect/i686-pc-windows-msvc/oxanus/index This example demonstrates the basic setup for an Oxanus application, including defining a custom worker and queue, enqueuing a job, and initializing the Oxanus worker system. It showcases the use of `Worker`, `Queue`, `Context`, `Config`, and `Storage` traits and structs. ```Rust use oxanus::{Worker, Queue, Context, Config, Storage}; use serde::{Serialize, Deserialize}; // Define your worker #[derive(Debug, Serialize, Deserialize)] struct MyWorker { data: String, } #[async_trait::async_trait] impl Worker for MyWorker { type Context = MyContext; type Error = MyError; async fn process(&self, ctx: &Context) -> Result<(), MyError> { // Process your job here Ok(()) } } // Define your queue #[derive(Serialize)] struct MyQueue; impl Queue for MyQueue { fn to_config() -> QueueConfig { QueueConfig::as_static("my_queue") } } // Define your context struct MyContext {} // Run your worker async fn run_worker() -> Result<(), OxanusError> { let ctx = Context::value(MyContext {}); let storage = Storage::builder().from_env()?.build()?; let config = Config::new(&storage) .register_queue::() .register_worker::(); // Enqueue some jobs storage.enqueue(MyQueue, MyWorker { data: "hello".into() }).await?; // Run the worker oxanus::run(config, ctx).await?; Ok(()) } ``` -------------------------------- ### Run Pre-Built Clap Example Source: https://docs.rs/tinyvec/latest/tinyvec/clap/^2 Provides shell commands to clone the `clap` repository, build a pre-built example, and run its help command to test the CLI functionality. ```Shell $ git clone https://github.com/clap-rs/clap && cd clap-rs/tests $ cargo build --release $ ./target/release/claptests --help ``` -------------------------------- ### Clone and Run Divan Examples Source: https://docs.rs/tinyvec/latest/tinyvec/divan/^0 Clone the Divan repository, navigate into the directory, and run the example benchmarks using `cargo bench`. This command executes all benchmarks within the `examples` package. ```Shell git clone https://github.com/nvzqz/divan.git cd divan cargo bench -q -p examples --all-features ``` -------------------------------- ### Example: Getting length of UninitSlice Source: https://docs.rs/tinyvec/latest/tinyvec/bytes/1.5.0/bytes/buf/struct.UninitSlice A Rust example demonstrating how to use the `len()` method on an `UninitSlice` to retrieve its byte count. The example includes an assertion to verify the returned length. ```Rust use bytes::BufMut; let mut data = [0, 1, 2]; let mut slice = &mut data[..]; let len = BufMut::chunk_mut(&mut slice).len(); assert_eq!(len, 3); ``` -------------------------------- ### Install Plotters Dependencies on Ubuntu Source: https://docs.rs/tinyvec/latest/tinyvec/crate/plotters/0.3.7/target-redirect/x86_64-unknown-linux-gnu/plotters/index Command to install necessary system dependencies for Plotters.rs on Ubuntu Linux, including `pkg-config`, `libfreetype6-dev`, and `libfontconfig1-dev`. ```Bash sudo apt install pkg-config libfreetype6-dev libfontconfig1-dev ``` -------------------------------- ### APIDOC: Struct PrimExample Source: https://docs.rs/tinyvec/latest/tinyvec/uiua An primitive code example. ```APIDOC struct PrimExample description: An primitive code example ``` -------------------------------- ### Install Plotters Dependencies on Ubuntu Linux Source: https://docs.rs/tinyvec/latest/tinyvec/plotters This command installs the necessary system-level dependencies for Plotters.rs on Ubuntu Linux, including `pkg-config`, `libfreetype6-dev`, and `libfontconfig1-dev` which are required for font rendering and other functionalities. ```Shell sudo apt install pkg-config libfreetype6-dev libfontconfig1-dev ``` -------------------------------- ### Minimal Rust Program with Default Clap Help/Version Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34 This minimal Rust program demonstrates how to initialize `clap` to automatically generate help and version information. It creates a new `App` instance, sets a name and version, and immediately calls `get_matches()` to process arguments. ```Rust extern crate clap; use clap::App; fn main() { App::new("fake").version("v1.0-beta").get_matches(); } ``` -------------------------------- ### Install Plotters Dependencies on Ubuntu Linux Source: https://docs.rs/tinyvec/latest/tinyvec/crate/plotters/0.3.7/target-redirect/x86_64-pc-windows-msvc/plotters/index This command installs the necessary system-level dependencies for Plotters.rs on Ubuntu Linux, including `pkg-config`, `libfreetype6-dev`, and `libfontconfig1-dev`, which are required for font rendering and configuration. ```Shell sudo apt install pkg-config libfreetype6-dev libfontconfig1-dev ``` -------------------------------- ### Clap Build Your Own Binary Test Commands Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/i686-pc-windows-msvc/clap/index Shell commands to create a new Rust project, add `clap` as a dependency, build the project, and run the resulting binary to test `clap`'s default auto-generated help/version features. ```Shell $ cargo new fake --bin && cd fake $ cargo build --release $ ./target/release/fake --help ``` -------------------------------- ### Rust `VariantAccess::unit_variant` Example Source: https://docs.rs/tinyvec/latest/tinyvec/serde/1.0.219/x86_64-unknown-linux-gnu/src/serde/de/mod.rs An example demonstrating the start of an implementation for the `unit_variant` method within a custom `VariantAccess` type `X`. This method is intended for deserializing enum variants that have no associated values. ```Rust # use serde::de::{self, value, DeserializeSeed, Visitor, VariantAccess, Unexpected}; # # struct X; # # impl<'de> VariantAccess<'de> for X { # type Error = value::Error; # fn unit_variant(self) -> Result<(), Self::Error> { ``` -------------------------------- ### Set Up Plotters Interactive Tutorial with Jupyter Source: https://docs.rs/tinyvec/latest/tinyvec/plotters This snippet provides the commands to clone the `plotters-doc-data` repository and launch a Jupyter Notebook server, enabling access to the interactive Plotters tutorial. It requires Jupyter and evcxr to be pre-installed. ```Shell git clone https://github.com/38/plotters-doc-data cd plotters-doc-data jupyter notebook ``` -------------------------------- ### API Documentation: log_to_defmt::setup Function Source: https://docs.rs/tinyvec/latest/tinyvec/log-to-defmt/*/log_to_defmt Documents the `setup` function, which configures the `log` crate's output to be forwarded to the `defmt` crate. This function initializes the logging adapter. ```APIDOC fn log_to_defmt::setup() Description: Set up log output to be forwarded to defmt ``` -------------------------------- ### Build and Run Minimal Clap Program Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/^2 Shell commands to build a Rust program using `cargo build --release` and then run it with `--help` or `--version` flags to test `clap`'s auto-generated output. ```Shell $ cargo build --release $ ./target/release/fake --help ``` -------------------------------- ### Rust Slice starts_with Example: Check for Prefix Source: https://docs.rs/tinyvec/latest/tinyvec/crate/bytes/1.5.0/target-redirect/x86_64-apple-darwin/bytes/struct.Bytes Demonstrates checking if a slice starts with a given prefix using `starts_with`. Includes examples with single and multiple elements, and non-matching prefixes. ```Rust let v = [10, 40, 30]; assert!(v.starts_with(&[10])); assert!(v.starts_with(&[10, 40])); assert!(!v.starts_with(&[50])); assert!(!v.starts_with(&[10, 50])); ``` -------------------------------- ### Connect to HTTP Website and GET Request with smol Source: https://docs.rs/tinyvec/latest/tinyvec/smol/^2 This Rust example demonstrates how to establish a TCP connection to an HTTP website (example.com:80), send a GET request, and pipe the server's response to standard output using the `smol` asynchronous runtime. It utilizes `smol::net::TcpStream` for networking and `smol::io::copy` for efficient data transfer. ```Rust use smol::{io, net, prelude::*, Unblock}; fn main() -> io::Result<()> { smol::block_on(async { let mut stream = net::TcpStream::connect("example.com:80").await?; let req = b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n"; stream.write_all(req).await?; let mut stdout = Unblock::new(std::io::stdout()); io::copy(stream, &mut stdout).await?; Ok(()) }) } ``` -------------------------------- ### Install Rebar Benchmarking Tool Source: https://docs.rs/tinyvec/latest/tinyvec/crate/regex/^1.6 Instructions to clone the `rebar` repository and install the benchmarking tool locally using Cargo. This tool is used to run and analyze performance benchmarks for the `regex` crate. ```bash git clone https://github.com/BurntSushi/rebar cd rebar cargo install --path ./ ``` -------------------------------- ### Run and Test Clap CLI Application Source: https://docs.rs/tinyvec/latest/tinyvec/clap/^4.2 Examples of running the compiled `clap` CLI application, showing the `--help` output and a basic invocation with a name argument. This demonstrates the automatically generated help message and the program's output based on parsed arguments. ```Shell $ demo --help A simple to use, efficient, and full-featured Command Line Argument Parser Usage: demo[EXE] [OPTIONS] --name Options: -n, --name Name of the person to greet -c, --count Number of times to greet [default: 1] -h, --help Print help -V, --version Print version $ demo --name Me Hello Me! ``` -------------------------------- ### Unstructured::len Method Example Source: https://docs.rs/tinyvec/latest/tinyvec/crate/arbitrary/1.4.1/target-redirect/x86_64-pc-windows-msvc/arbitrary/struct.Unstructured Example showing how to use the `len` method to get the number of remaining bytes in an `Unstructured` instance. It illustrates how generating an arbitrary value consumes bytes and reduces the available length. ```Rust use arbitrary::{Arbitrary, Unstructured}; let mut u = Unstructured::new(&[1, 2, 3]); // Initially have three bytes of data. assert_eq!(u.len(), 3); // Generating a `bool` consumes one byte from the underlying data, so // we are left with two bytes afterwards. let _ = bool::arbitrary(&mut u); assert_eq!(u.len(), 2); ``` -------------------------------- ### Minimal Rust Program for Clap Auto-Generated Help/Version Source: https://docs.rs/tinyvec/latest/tinyvec/clap/%7E2 A minimal `src/main.rs` file for a Rust project demonstrating how to set up a basic `clap` application that automatically provides `--help` and `--version` functionality. ```Rust extern crate clap; use clap::App; fn main() { App::new("fake").version("v1.0-beta").get_matches(); } ``` -------------------------------- ### Multiaxis Plotting Example in Rust Source: https://docs.rs/tinyvec/latest/tinyvec/criterion-plot/^0.5 This snippet introduces a function `tf` that returns a complex number, likely for a transfer function plot. It sets up start and end ranges for plotting, indicating a multiaxis plot scenario. ```Rust use std::f64::consts::PI; use itertools_num::linspace; use num_complex::Complex; use criterion_plot::prelude::*; fn tf(x: f64) -> Complex { Complex::new(0., x) / Complex::new(10., x) / Complex::new(1., x / 10_000.) } let (start, end): (f64, f64) = (1.1, 90_000.); ``` -------------------------------- ### Build and Run Custom Clap Application Source: https://docs.rs/tinyvec/latest/tinyvec/clap/%7E2 Shell commands to build a newly created Rust project with `clap` and run it to test its auto-generated help or version output. ```Shell $ cargo build --release $ ./target/release/fake --help ``` -------------------------------- ### Complete Example for Criterion.rs Benchmarking with `criterion_main` Source: https://docs.rs/tinyvec/latest/tinyvec/crate/criterion/0.3.6/target-redirect/x86_64-apple-darwin/criterion/macro.criterion_main A comprehensive Rust example demonstrating the setup of a Criterion.rs benchmark. It shows how to import the crate, define benchmark functions, group them using `criterion_group!`, and run them with `criterion_main!`. ```Rust #[macro_use] extern crate criterion; use criterion::Criterion; fn bench_method1(c: &mut Criterion) { } fn bench_method2(c: &mut Criterion) { } criterion_group!(benches, bench_method1, bench_method2); criterion_main!(benches); ``` -------------------------------- ### Set up Jupyter Notebook for Plotters Interactive Tutorial Source: https://docs.rs/tinyvec/latest/tinyvec/crate/plotters/0.3.7/target-redirect/i686-pc-windows-msvc/plotters/index Instructions to clone the plotters-doc-data repository and start a Jupyter notebook for an interactive Plotters tutorial using the evcxr kernel. Requires Jupyter and evcxr to be pre-installed. ```Shell git clone https://github.com/38/plotters-doc-data cd plotters-doc-data jupyter notebook ``` -------------------------------- ### Clap Generated CLI Help Output Example Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/i686-pc-windows-msvc/clap/index Example output generated by `clap` when running a compiled program with the `--help` flag. It displays the application's version, author, description, usage syntax, flags, options, arguments, and subcommands, demonstrating `clap`'s automatic help generation. ```CLI Output $ myprog --help My Super Program 1.0 Kevin K. Does awesome things USAGE: MyApp [FLAGS] [OPTIONS] [SUBCOMMAND] FLAGS: -h, --help Prints this message -v Sets the level of verbosity -V, --version Prints version information OPTIONS: -c, --config Sets a custom config file ARGS: INPUT The input file to use SUBCOMMANDS: help Prints this message test Controls testing features ``` -------------------------------- ### Get Reference to LinkedHashMap Value (Rust APIDOC) Source: https://docs.rs/tinyvec/latest/tinyvec/linked-hash-map/*/linked_hash_map/struct.LinkedHashMap Documents the `get` method for `LinkedHashMap`, which retrieves an immutable reference to the value associated with a given key. Includes a Rust example demonstrating value retrieval. ```APIDOC pub fn get(&self, k: &Q) -> Option<&V> where K: Borrow, Q: Eq + Hash + ?Sized, Parameters: k: &Q - The key to retrieve the value for. Returns: Option<&V> - An Option containing a reference to the value if the key exists, otherwise None. ``` ```Rust use linked_hash_map::LinkedHashMap; let mut map = LinkedHashMap::new(); map.insert(1, "a"); map.insert(2, "b"); map.insert(2, "c"); map.insert(3, "d"); assert_eq!(map.get(&1), Some(&"a")); assert_eq!(map.get(&2), Some(&"c")); ``` -------------------------------- ### Create a new Rust project for regex-lite example Source: https://docs.rs/tinyvec/latest/tinyvec/regex-lite Commands to initialize a new Rust project directory, navigate into it, and set up the basic project structure using `cargo init`. ```bash mkdir regex-example cd regex-example cargo init ``` -------------------------------- ### Example: Getting Shared Spare Slice from SliceVec in Rust Source: https://docs.rs/tinyvec/latest/tinyvec/crate/tinyvec/latest/target-redirect/i686-pc-windows-msvc/src/tinyvec/slicevec.rs A Rust example demonstrating `SliceVec::grab_spare_slice`. It shows how to access the unused portion of the backing array as a shared slice and how its length changes as elements are added to the `SliceVec`. ```Rust let mut arr = [0; 4]; let mut sv = SliceVec::from_slice_len(&mut arr, 0); assert_eq!(sv.grab_spare_slice().len(), 4); sv.push(10); sv.push ``` -------------------------------- ### Example CLI Help Output for Clap Application Source: https://docs.rs/tinyvec/latest/tinyvec/clap/2.9 This snippet shows the formatted help message generated by a `clap`-powered command-line application when executed with `--help`. It details the application's name, version, author, usage syntax, available flags, options, arguments, and subcommands, providing comprehensive user guidance. ```Bash $ myprog --help My Super Program 1.0 Kevin K. Does awesome things USAGE: MyApp [FLAGS] [OPTIONS] [SUBCOMMAND] FLAGS: -h, --help Prints this message -v Sets the level of verbosity -V, --version Prints version information OPTIONS: -c, --config Sets a custom config file ARGS: INPUT The input file to use SUBCOMMANDS: help Prints this message test Controls testing features ``` -------------------------------- ### Rust Criterion: Benchmarking with iter_batched for Setup Source: https://docs.rs/tinyvec/latest/tinyvec/crate/criterion/latest/target-redirect/x86_64-unknown-linux-gnu/criterion/struct.Bencher This Rust example illustrates the use of `b.iter_batched` to benchmark a sorting algorithm. It demonstrates how to provide a setup function (`create_scrambled_data`) that runs once per batch, ensuring the sorting routine receives fresh, unsorted data without timing the setup overhead on each iteration. ```Rust use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; fn create_scrambled_data() -> Vec { // ... } // The sorting algorithm to test fn sort(data: &mut [u64]) { // ... } fn bench(c: &mut Criterion) { let data = create_scrambled_data(); c.bench_function("with_setup", move |b| { // This will avoid timing the clone call. b.iter_batched(|| data.clone(), |mut data| sort(&mut data), BatchSize::SmallInput) }); } criterion_group!(benches, bench); criterion_main!(benches); ``` -------------------------------- ### Run Clap Library Tests Source: https://docs.rs/tinyvec/latest/tinyvec/clap/2.9 Commands to execute tests for the `clap` library, including running standard tests, tests with the 'yaml' feature, and building with 'lints'. ```bash $ cargo test && make -C clap-tests test $ cargo test --features yaml $ cargo build --features lints ``` -------------------------------- ### Femme start Function API Reference Source: https://docs.rs/tinyvec/latest/tinyvec/femme/^2.1 API documentation for the `start` function in the `femme` crate. This function initializes the logger based on the current environment. ```APIDOC fn start(): description: Starts logging depending on current environment. ``` -------------------------------- ### Get Typed Value or Exit Macro: value_t_or_exit Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/i686-pc-windows-msvc/clap/index A convenience macro for getting a typed value `T` where `T` implements `std::str::FromStr`. Unlike `value_t`, this macro exits the application upon a parsing error instead of returning a `Result` type. ```APIDOC value_t_or_exit Convenience macro getting a typed value `T` where `T` implements `std::str::FromStr` or exiting upon error, instead of returning a `Result` type. ``` -------------------------------- ### Create a Basic Actix Web Server with Path Parameters Source: https://docs.rs/tinyvec/latest/tinyvec/actix-web/^3 This example demonstrates how to set up a simple web server using Actix Web. It defines an asynchronous route that extracts `id` (u32) and `name` (String) from the URL path, then returns a formatted greeting. The `#[actix_web::main]` macro is used to run the asynchronous main function, binding the server to `127.0.0.1:8080`. ```Rust use actix_web::{get, web, App, HttpServer, Responder}; #[get("/{id}/{name}/index.html")] async fn index(web::Path((id, name)): web::Path<(u32, String)>) -> impl Responder { format!("Hello {}! id:{}", name, id) } #[actix_web::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| App::new().service(index)) .bind("127.0.0.1:8080")? .run() .await } ``` -------------------------------- ### Get Multiple Typed Values Macro: values_t Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/i686-pc-windows-msvc/clap/index A convenience macro for getting a `Vec` of typed values where `T` implements `std::str::FromStr`. This macro returns a `clap::Result>`, giving the developer control over error handling for failed parses. ```APIDOC values_t Convenience macro getting a typed value `Vec` where `T` implements `std::str::FromStr` This macro returns a `clap::Result>` which allows you as the developer to decide what you’d like to do on a failed parse. ``` -------------------------------- ### app_from_crate Macro Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/x86_64-pc-windows-msvc/clap/index Allows you to build the `App` instance from your Cargo.toml at compile time. ```Rust app_from_crate!() ``` -------------------------------- ### Setting Up a Multi-Axis Plot with criterion_plot in Rust Source: https://docs.rs/tinyvec/latest/tinyvec/crate/criterion-plot/0.4.5/target-redirect/x86_64-apple-darwin/criterion_plot/index Provides an example of setting up a plot with multiple axes, specifically demonstrating a transfer function (`tf`) using `num_complex`. This snippet shows the initial setup for defining the function and the range for a multi-axis plot. ```Rust use std::f64::consts::PI; use itertools_num::linspace; use num_complex::Complex; use criterion_plot::prelude::*; fn tf(x: f64) -> Complex { Complex::new(0., x) / Complex::new(10., x) / Complex::new(1., x / 10_000.) } let (start, end): (f64, f64) = (1.1, 90_000.); ``` -------------------------------- ### Example TOML Configuration Structure Source: https://docs.rs/tinyvec/latest/tinyvec/crate/toml/latest/target-redirect/i686-pc-windows-msvc/toml/index Illustrates a basic TOML configuration file structure, commonly used for project metadata and dependencies. ```TOML [package] name = "toml" [dependencies] serde = "1.0" ``` -------------------------------- ### Perform a GET Request and Directly Receive Body as String (Surf) Source: https://docs.rs/tinyvec/latest/tinyvec/surf/^2.0 Shows a more concise way to perform a GET request and directly receive the response body as a string, skipping the intermediate `Response` object for simpler use cases. ```Rust dbg!(surf::get("https://httpbin.org/get").recv_string().await?); ``` -------------------------------- ### Perform a GET Request and Read Body as String (Surf) Source: https://docs.rs/tinyvec/latest/tinyvec/surf/^2.0 Demonstrates how to make a basic GET request to a URL using `surf::get` and retrieve the response body as a string. It shows the intermediate `Response` object before accessing the body. ```Rust let mut res = surf::get("https://httpbin.org/get").await?; dbg!(res.body_string().await?); ``` -------------------------------- ### Build App from Crate Macro: app_from_crate Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/i686-pc-windows-msvc/clap/index Allows you to build the `App` instance from your Cargo.toml at compile time, simplifying application metadata integration. ```APIDOC app_from_crate Allows you to build the `App` instance from your Cargo.toml at compile time. ``` -------------------------------- ### Get Multiple Typed Values or Exit Macro: values_t_or_exit Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/i686-pc-windows-msvc/clap/index A convenience macro for getting a `Vec` of typed values where `T` implements `std::str::FromStr`. This macro exits the application upon a parsing error, providing a simpler error handling mechanism than `values_t`. ```APIDOC values_t_or_exit Convenience macro getting a typed value `Vec` where `T` implements `std::str::FromStr` or exiting upon error. ``` -------------------------------- ### Build and Run Minimal Clap App Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/i686-unknown-linux-gnu/clap/index Commands to compile the minimal `clap` application and run it with `--help` or `--version` flags to see the auto-generated output provided by `clap`. ```Shell $ cargo build --release $ ./target/release/fake --help ``` -------------------------------- ### Clap CLI: Builder Pattern Fragment - Get Matches Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/x86_64-unknown-linux-gnu/clap/index A fragment of a `clap` builder pattern chain, showing the final `get_matches()` call after defining version, author, and an argument from usage. This snippet is a continuation of a larger builder example. ```Rust .version("1.3") .author("Someone E. ") .arg_from_usage("-d, --debug 'Print debug information'")) .get_matches(); // Same as previous example... } ``` -------------------------------- ### Run Tests for Clap with Feature Configurations Source: https://docs.rs/tinyvec/latest/tinyvec/clap/%7E2 These commands demonstrate how to execute tests for the `clap` library, allowing for scenarios where default features are disabled or specific optional features are enabled for testing. ```Shell $ cargo test --no-default-features ``` ```Shell $ cargo test --features "yaml unstable" ``` -------------------------------- ### Get Typed Value Macro: value_t Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/i686-pc-windows-msvc/clap/index A convenience macro for getting a single typed value `T` from an argument, where `T` implements `std::str::FromStr`. It returns a `Result`, allowing the developer to handle parse failures or missing arguments. Can be used for single values or as an iterator. ```APIDOC value_t Convenience macro getting a typed value `T` where `T` implements `std::str::FromStr` from an argument value. This macro returns a `Result` which allows you as the developer to decide what you’d like to do on a failed parse. There are two types of errors, parse failures and those where the argument wasn’t present (such as a non-required argument). You can use it to get a single value, or a iterator as with the `ArgMatches::values_of` ``` -------------------------------- ### Rust Clap CLI: Builder Pattern Continuation Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/x86_64-apple-darwin/clap/index A continuation of a `clap` builder pattern example, showing how to define version, author, and an argument using `arg_from_usage` before parsing matches. ```Rust .version("1.3") .author("Someone E. ") .arg_from_usage("-d, --debug 'Print debug information'")) .get_matches(); ``` -------------------------------- ### Example: Mutating IndexMap Elements by Key Source: https://docs.rs/tinyvec/latest/tinyvec/crate/indexmap/latest/target-redirect/x86_64-unknown-linux-gnu/indexmap/map/struct.IndexMap Demonstrates how to use key-based indexing to get a mutable reference to a value in an `IndexMap` and modify it. The first example shows successful mutation, while the second shows a panic when attempting to insert a new key via indexing. ```Rust use indexmap::IndexMap; let mut map = IndexMap::new(); for word in "Lorem ipsum dolor sit amet".split_whitespace() { map.insert(word.to_lowercase(), word.to_string()); } let lorem = &mut map["lorem"]; assert_eq!(lorem, "Lorem"); lorem.retain(char::is_lowercase); assert_eq!(map["lorem"], "orem"); ``` ```Rust use indexmap::IndexMap; let mut map = IndexMap::new(); map.insert("foo", 1); map["bar"] = 1; // panics! ``` -------------------------------- ### Clap Modules API Reference Source: https://docs.rs/tinyvec/latest/tinyvec/clap/^4.2 Reference documentation for key modules within the `clap` crate, including `_cookbook`, `_derive`, `_faq`, `_features`, `_tutorial`, `builder`, `error`, and `parser`. Each entry provides a brief description of the module's purpose and functionality. ```APIDOC _cookbook: Documentation: Cookbook _derive: Documentation: Derive Reference _faq: Documentation: FAQ _features: Documentation: Feature Flags _tutorial: Tutorial for the Builder API builder: Define Command line arguments error: Error reporting parser: Command line argument parser ``` -------------------------------- ### Set up Jupyter Notebook for Plotters Tutorial Source: https://docs.rs/tinyvec/latest/tinyvec/plotters/^0.3 Instructions to clone the plotters-doc-data repository and start a Jupyter Notebook server to access the interactive tutorial for Plotters using evcxr. ```Shell git clone https://github.com/38/plotters-doc-data cd plotters-doc-data jupyter notebook ``` -------------------------------- ### Example: Get Native-Endian f64 from bytes::Buf Source: https://docs.rs/tinyvec/latest/tinyvec/bytes/1.5.0/bytes/buf/trait.Buf Illustrates how to use the `get_f64_ne` method to extract a native-endian 64-bit floating-point number from a byte buffer. The example dynamically sets the byte order based on the target system's endianness. ```Rust use bytes::Buf; let mut buf: &[u8] = match cfg!(target_endian = "big") { true => b"\x3F\xF3\x33\x33\x33\x33\x33\x33 hello", false => b"\x33\x33\x33\x33\x33\x33\xF3\x3F hello", }; assert_eq!(1.2f64, buf.get_f64_ne()); ``` -------------------------------- ### Rust Criterion: BenchmarkGroup Usage Examples Source: https://docs.rs/tinyvec/latest/tinyvec/crate/criterion/latest/target-redirect/x86_64-unknown-linux-gnu/criterion/struct.BenchmarkGroup Provides comprehensive examples for using `BenchmarkGroup` in the `criterion` crate, covering simple function benchmarking, nested benchmarks with custom parameters, and throughput measurement for data processing functions. Includes setup with `criterion_group!` and `criterion_main!`. ```Rust use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use std::time::Duration; fn bench_simple(c: &mut Criterion) { let mut group = c.benchmark_group("My Group"); // Now we can perform benchmarks with this group group.bench_function("Bench 1", |b| b.iter(|| 1 )); group.bench_function("Bench 2", |b| b.iter(|| 2 )); // It's recommended to call group.finish() explicitly at the end, but if you don't it will // be called automatically when the group is dropped. group.finish(); } fn bench_nested(c: &mut Criterion) { let mut group = c.benchmark_group("My Second Group"); // We can override the configuration on a per-group level group.measurement_time(Duration::from_secs(1)); // We can also use loops to define multiple benchmarks, even over multiple dimensions. for x in 0..3 { for y in 0..3 { let point = (x, y); let parameter_string = format!("{} * {}", x, y); group.bench_with_input(BenchmarkId::new("Multiply", parameter_string), &point, |b, (p_x, p_y)| b.iter(|| p_x * p_y)); } } group.finish(); } fn bench_throughput(c: &mut Criterion) { let mut group = c.benchmark_group("Summation"); for size in [1024, 2048, 4096].iter() { // Generate input of an appropriate size... let input = vec![1u64, *size]; // We can use the throughput function to tell Criterion.rs how large the input is // so it can calculate the overall throughput of the function. If we wanted, we could // even change the benchmark configuration for different inputs (eg. to reduce the // number of samples for extremely large and slow inputs) or even different functions. group.throughput(Throughput::Elements(*size as u64)); group.bench_with_input(BenchmarkId::new("sum", *size), &input, |b, i| b.iter(|| i.iter().sum::())); group.bench_with_input(BenchmarkId::new("fold", *size), &input, |b, i| b.iter(|| i.iter().fold(0u64, |a, b| a + b))); } group.finish(); } criterion_group!(benches, bench_simple, bench_nested, bench_throughput); criterion_main!(benches); ``` -------------------------------- ### Run Tests Using Just Command Runner Source: https://docs.rs/tinyvec/latest/tinyvec/clap/%7E2 This command shows how to execute the project's tests using the `just` command runner, which simplifies common development tasks by bundling commands. ```Shell $ just run-tests ``` -------------------------------- ### Basic Clap Application in Rust Source: https://docs.rs/tinyvec/latest/tinyvec/clap/2.9 Demonstrates a minimal Rust program using `clap` to create a command-line application named 'fake' with a version 'v1.0-beta'. ```rust extern crate clap; use clap::App; fn main() { App::new("fake").version("v1.0-beta").get_matches(); } ``` -------------------------------- ### APIDOC: serde_with::guide Module Source: https://docs.rs/tinyvec/latest/tinyvec/serde_with/1 Serves as the user guide for the `serde_with` crate. It provides comprehensive documentation and examples for using the library effectively. ```APIDOC Module: guide Description: serde_with User Guide ``` -------------------------------- ### Rust Project Setup for Regex Crate Source: https://docs.rs/tinyvec/latest/tinyvec/crate/regex/1.11.1/target-redirect/x86_64-pc-windows-msvc/regex/index Demonstrates the initial steps to set up a new Rust project, including creating a directory, navigating into it, and initializing a Cargo project. ```Shell $ mkdir regex-example $ cd regex-example $ cargo init ``` -------------------------------- ### APIDOC: Struct Values Source: https://docs.rs/tinyvec/latest/tinyvec/crate/clap/2.34.0/target-redirect/i686-unknown-linux-gnu/clap/index An iterator for getting multiple values out of an argument via the `ArgMatches::values_of` method. ```APIDOC struct Values Description: Iterator for getting multiple argument values via ArgMatches::values_of. ``` -------------------------------- ### clap::Values Struct Source: https://docs.rs/tinyvec/latest/tinyvec/clap/2.9 An iterator for getting multiple values out of an argument via the [`ArgMatches::values_of`](./struct.ArgMatches.html#method.values_of) method. ```APIDOC struct Values Description: An iterator for getting multiple values out of an argument via the [`ArgMatches::values_of`](./struct.ArgMatches.html#method.values_of) method. ```