Hi I'm struggling to get the doc tests to work out that the function it is documenting actually exists.
it's in a public module, and implements a trait called Parser, which provides the required parse_s method.
/// A function for parsing integers
/// ```
/// use gobble::*;
/// let r = common_int.parse_s("32").unwrap();
/// assert_eq!(r,32);
/// ```
///
pub fn common_int<'a>(it: &LCChars<'a>) -> ParseRes<'a, isize> {
//TODO add and mul without panic
let mut it = it.clone();
let (minus, mut res) = match it.next() {
Some('-') => (-1, 0),
Some(v) if v >= '0' && v <= '9' => (1, (v as isize - '0' as isize)),
_ => return it.err_cr(ECode::SMess("Not an int")),
};
let mut it2 = it.clone();
loop {
match it.next() {
Some(v) if v >= '0' && v <= '9' => {
res = res
.checked_mul(10)
.ok_or(it.err_c(ECode::SMess("Num too big")))?
.checked_add(v as isize - '0' as isize)
.ok_or(it.err_c(ECode::SMess("Num too big")))?;
it2 = it.clone();
}
_ => return Ok((it2, minus * res)),
}
}
}
When called from a local test this function works, called from the doctest it fails to find it and I get the following error:
---- src/common.rs - common::common_int (line 7) stdout ----
error[E0425]: cannot find value `common_int` in this scope
--> src/common.rs:9:9
|
5 | let r = common_int.parse_s("32").unwrap();
| ^^^^^^^^^^ help: a function with a similar name exists: `common_str`
|
::: /home/matthew/bdata/CargoTarget/package/gobble-0.1.3/src/reader.rs:201:1
|
common_str is a different function in another module, I have made this module public in the lib.rs:
Any ideas?