Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Welcome!

LinkedIn GitHub Itch.io

This is a landing page to look at other projects and bits I've noodled away at...

autospy

🎵 autospy record, autospy replace 🎵

Crates.io Version docs.rs GitHub Actions Workflow Status MIT

A test spy object library.

Overview

A test spy is a type of test double used in unit testing. It provides the same interface as the production code, but allow you to set outputs before use in a test and to verify input parameters after the spy has been used.

#[autospy] generates a test spy object for traits.

Usage

The example below demonstrates use in a unit test assuming autospy is included in [dev-dependencies].

#![allow(unused)]
fn main() {
#[cfg(test)]
use autospy::autospy;

#[cfg_attr(test, autospy)]
trait MyTrait {
    fn foo(&self, x: u32) -> bool;
}

fn use_trait(trait_object: impl MyTrait) -> bool {
    trait_object.foo(10)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_trait() {
        let spy = MyTraitSpy::default(); // build spy
        
        spy.foo.returns.push_back(true); // set the return value

        assert!(use_trait(spy.clone())); // use the spy
        assert_eq!(vec![10], spy.foo.arguments.take_all()) // verify the arguments passed
    }
}
}

For additional examples and features see the docs.

Acknowledgements

Autospy is heavily influenced by the excellent mockall crate, which, through automock, provides many similar features.

Autospy aims to offer these features through a macro-generated spy object, rather than a mock object. The use of either is largely personal preference; however, there are some advantages to using a spy object:

Test objectTest failuresTest structureComplexity
MockPanics if expectations fail; error messages can be unclearLess standard pattern, expectations are baked into objectMore crate-specific syntax and usage patterns
SpyAsserts like any regular testAssert after use, more standard test patternSimple: set what's returned, then inspect what was called

licenses

crates.io GitHub Actions Workflow Status MIT

Cargo subcommand for collecting licenses.

Install

$ cargo install licenses

Usage

$ cargo licenses --help
Usage: cargo licenses [OPTIONS] <COMMAND>

Commands:
  collect  Collects all licenses into a folder
  summary  Provides a summary of all licenses

Options:
  -d, --dev                  Include dev dependencies [default: excluded]
  -b, --build                Include build dependencies [default: excluded]
  -D, --depth <DEPTH>        The depth of dependencies to include [default: all sub dependencies]
  -e, --exclude <WORKSPACE>  Exclude specified workspace [default: all included]
  -i, --ignore <CRATE>       Ignore specified crate [default: all included]
  -h, --help                 Print help

Examples

Collect

$ cargo licenses collect --depth 1
licenses
├── anyhow-LICENSE-APACHE
├── anyhow-LICENSE-MIT
├── cargo_metadata-LICENSE-MIT
├── clap-LICENSE-APACHE
├── clap-LICENSE-MIT
├── colored-LICENSE
├── itertools-LICENSE-APACHE
├── itertools-LICENSE-MIT
├── serde_json-LICENSE-APACHE
└── serde_json-LICENSE-MIT

Summary

$ cargo licenses summary --depth 1
MIT: cargo_metadata
MIT OR Apache-2.0: anyhow,clap,itertools,serde_json
MPL-2.0: colored
$ cargo licenses summary --depth 1 --json
{
  "MPL-2.0": [
    "colored"
  ],
  "MIT": [
    "cargo_metadata"
  ],
  "MIT OR Apache-2.0": [
    "anyhow",
    "clap",
    "itertools",
    "serde_json"
  ]
}

trust-list

crates.io GitHub Actions Workflow Status MIT

Command line tool for generating a dependency information table in markdown.

Install

cargo install trust-list

Usage

$ trust-list --help
Command line tool for generating a dependency information table in markdown

Usage: trust-list [OPTIONS]

Options:
  -o, --output-file <OUTPUT_FILE>  The output filename, appended with .md [default: trust-list]
  -r, --recreate                   Recreate table [default: appends new dependencies]
  -D, --depth <DEPTH>              The depth of dependencies to collect information on [default: all sub dependencies]
  -d, --dev                        Include dev dependencies [default: excluded]
  -b, --build                      Include build dependencies [default: excluded]
  -e, --exclude <EXCLUDE>          Exclude specified workspace [default: all included]
  -h, --help                       Print help
  -V, --version                    Print version

Example

trust-list --depth 1
namedownloadscontributorsreverse_dependenciesversionscreated_atupdated_atrepository
anyhow362544609232067610005/10/201914/04/2025https://github.com/dtolnay/anyhow
chrono31649012030+147859120/11/201429/04/2025https://github.com/chronotope/chrono
clap45566895130+2273643301/03/201509/06/2025https://github.com/clap-rs/clap
field_names53419012308/01/202104/01/2022https://github.com/TedDriggs/field_names
itertools53815080330+651713021/11/201431/12/2024https://github.com/rust-itertools/itertools
pbr2573309261022414/10/201508/02/2023https://github.com/a8m/pb
reqwest23678644330+1250211316/10/201601/07/2025https://github.com/seanmonstar/reqwest
serde57230214730+5208630605/12/201409/03/2025https://github.com/serde-rs/serde
serde_json49851097330+3611717207/08/201503/03/2025https://github.com/serde-rs/json

Compliance

Restricted to one request per second as per: crates.io data access policy

redacta

crates.io GitHub Release GitHub Actions Workflow Status MIT

Command line tool for redacting information from text.

[!WARNING] This is an early stage implementation, it might not redact accurately.

Install

curl -sS https://raw.githubusercontent.com/lhalf/redacta/main/install.sh | sh

Or install via cargo:

cargo install redacta

Usage

Takes text via stdin and forwards redacted text to stdout.

$ redacta --help
Usage: <STDIN> | redacta [OPTIONS]

Options:
      --ipv4           Enable IPv4 redaction
      --ipv6           Enable IPv6 redaction
      --fqdn           Enable FQDN redaction
  -r, --regex <REGEX>  Regex redaction
  -h, --help           Print help

Example

$ echo "Look at my 192.168.0.1 IP!" | redacta --ipv4
Look at my *********** IP!
$ echo "No really, look at my 2001:db8:3333:4444:5555:6666:7777:8888 IP!" | redacta --ipv6
No really, look at my ************************************** IP!
$ echo "Okay, it is example.server.com here..." | redacta --fqdn
Okay, it is ****************** here...