Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/geky/cargo-what
Tells you what type things are
https://github.com/geky/cargo-what
Last synced: 1 day ago
JSON representation
Tells you what type things are
- Host: GitHub
- URL: https://github.com/geky/cargo-what
- Owner: geky
- License: mit
- Created: 2020-10-17T15:01:39.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-19T06:49:28.000Z (about 4 years ago)
- Last Synced: 2024-10-21T01:34:45.914Z (about 1 month ago)
- Language: Rust
- Size: 22.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
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.``` rust
fn hello() -> Result<(), Box> {
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`.
``` bash
$ cargo what
hole: expecting `std::result::Result<(), Box>`
--> 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`:``` bash
$ 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.``` rust
fn hello(a: usize, b: usize) -> usize {
let c = a..b;
what!(a, b, c)
}
```And with `cargo what`:
```bash
$ 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`
```Emacs keybindings left as an exercise to the reader.
[`todo!`]: https://doc.rust-lang.org/std/macro.todo.html