| Crates.io | icecream |
| lib.rs | icecream |
| version | 0.1.0 |
| created_at | 2018-02-27 08:54:53.549011+00 |
| updated_at | 2018-04-08 08:18:56.327577+00 |
| description | Print debugging with inspection. |
| homepage | https://github.com/ericchang00/icecream-rs |
| repository | https://github.com/ericchang00/icecream-rs |
| max_upload_size | |
| id | 53016 |
| size | 14,492 |
Print debugging with inspection for Rust, inspired by icecream for Python.
I tend to use a lot of print debugging when writing Rust. icecream provides the ic!() and ice!() macros to make print debugging more convenient, by formatting print statements with helpful information like:
line number
calling function
module name
file name
ic!()// src/example.rs
#[macro_use]
extern crate icecream;
mod a_module {
fn some_function() {
let x = Some(99);
ic!();
ic!(x);
ic!(x.unwrap() + 1);
ice!();
}
}
ic!() prints the filename and line number.
example.rs:8 ❯
ic!(x) prints the name of the variable and the value formatted with std::fmt::Debug.
example.rs:9 ❯ x = Some(99)
ic!(x.unwrap() + 1) evaluates the inner expression and prints the resulting value.
example.rs:10 ❯ x.unwrap() + 1 = 100
ice!() prints a longer output that includes the calling module and function.
example.rs::a_module::some_function:11 ❯
ic!()You can also configure the characters used for symbols in the print output.
// main.rs
#[macro_use]
extern crate icecream;
fn main() {
icecream::set_equals_symbol(" -> ");
let x = 1;
ic!(x);
}
main.rs:7 ❯ x -> 1
Tests must be run single-threaded with the --nocapture flag.
RUST_TEST_THREADS=1 cargo test -- --nocapture