How can I add example code to a private method's documentation?

Viewed 122

When documenting module internal functions, I'd like to put some example code in it:

// in private module foo

/// This functions does something etc.
/// Example:
/// ```
/// use mylib::foo::my_func;
/// assert_eq!(my_func(2), 3);
/// ```
fn my_func(x: i32) -> i32 {
    3
}

Running cargo test does not work because foo is private (and should be) so I get a lot of failing tests.

I read about putting ignore tags on the code snippet, however this does not seem to be a good solution, as I'd prefer having the code checked.

What is the proper way to handle such a situation?

0 Answers
Related