3 unstable releases

Uses old Rust 2015

0.1.0 Apr 8, 2018
0.0.2 Feb 28, 2018
0.0.1 Feb 27, 2018

#13 in #ic

Download history 39/week @ 2023-12-14 18/week @ 2023-12-21 11/week @ 2023-12-28 16/week @ 2024-01-04 14/week @ 2024-01-11 3/week @ 2024-01-18 6/week @ 2024-01-25 3/week @ 2024-02-01 6/week @ 2024-02-08 23/week @ 2024-02-15 41/week @ 2024-02-22 33/week @ 2024-02-29 36/week @ 2024-03-07 29/week @ 2024-03-14 21/week @ 2024-03-21 34/week @ 2024-03-28

121 downloads per month

MIT license

12KB
201 lines

icecream-rs

Build Status

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

Debugging with 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!();
    }
}

Plain

ic!() prints the filename and line number.

example.rs:8

Matching on an identifier

ic!(x) prints the name of the variable and the value formatted with std::fmt::Debug.

example.rs:9 ❯ x = Some(99)

Matching on an expression

ic!(x.unwrap() + 1) evaluates the inner expression and prints the resulting value.

example.rs:10 ❯ x.unwrap() + 1 = 100

Printing more information

ice!() prints a longer output that includes the calling module and function.

example.rs::a_module::some_function:11

Configuring 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

Tests must be run single-threaded with the --nocapture flag.

RUST_TEST_THREADS=1 cargo test -- --nocapture

Dependencies

~2.4–3.5MB
~71K SLoC