I’m new to Rust and implementing a list library for familiarisation. So far the normal unit tests run correctly, but when I started writing doc tests, they resulted in what seems to be a runtime error.
I use the command cargo test --doc
to kick it off, but it results in the following error:
error: doctest failed, to rerun pass `--doc`
Caused by:
process didn't exit successfully: `rustdoc --edition=2021 --crate-type lib --crate-name cons_list --test src/lib.rs --test-run-directory ... -L dependency=... --extern cons_list=... -C embed-bitcode=no --error-format human`
signal: 5, SIGTRAP: trace/breakpoint trap)
Doctests seem to run but the moment I try introducing my own type, rustdoc
fails. so e.g. a test like assert_eq!(1, 1);
works fine, but the moment I start referring to my own type it seems to result in rustdoc
failing.
List definition
#[derive(Debug, Default, PartialEq, PartialOrd)]
pub enum List<T> {
#[default]
Nil,
Cons(T, Box<List<T>>),
}
The test in question
Even one line doesn’t work, let alone adding any assert
s
/// Creates a new empty list of type List<T>
/// ```
/// let list: List<i32> = List::new();
/// ```
pub fn new() -> List<T> {
Nil
}
I’m really not certain what to do here. Any ideas?