cargo-what

Crates.iocargo-what
lib.rscargo-what
version0.1.3
sourcesrc
created_at2020-10-17 15:20:42.949788
updated_at2020-10-19 06:50:59.257355
descriptionTells you what type things are
homepage
repositoryhttps://github.com/geky/cargo-what
max_upload_size
id301450
size30,332
Christopher Haster (geky)

documentation

https://docs.rs/cargo-what

README

What?

Tells you what type things are.

This crate provides the what! macro. This is functionally similar to the todo! macro, except that it also tells you type information.

fn hello() -> Result<(), Box<dyn Error>> {
    what!()
}

Just like todo!, what! passes all type-checks and makes it easy to write/build/test unfinished code. If it ever ends up in a compiled program, attempted to execute a what! will panic.

The fun part happens when you run cargo what.

$ cargo what
hole: expecting `std::result::Result<(), Box<dyn std::error::Error>>`
 --> src/hello.rs
  |
2 |     what!()
  |     ^^^^^^^

Unfortunately, custom diagnostics aren't really available to Rust libraries, requiring the extra command. cargo what can be installed with cargo:

$ cargo install cargo-what

cargo what wraps cargo build to show the type-info of any what!s you have in your code.

what! also accepts arguments and shows their types, which can be useful for reducing the "unused variable" noise.

fn hello(a: usize, b: usize) -> usize {
    let c = a..b;
    what!(a, b, c)
}

And with cargo what:

$ cargo what
hole: expecting `usize`
 --> src/hello.rs
  |
3 |     what!(a, b, c)
  |     ^^^^^^^^^^^^^^
  |
  = note: a is `usize`
  = note: b is `usize`
  = note: c is `std::ops::Range<usize>`

Emacs keybindings left as an exercise to the reader.

Commit count: 14

cargo fmt