Disable line numbers on a specific doctest/example?

⚓ Rust    📅 2025-07-26    👤 surdeus    👁️ 3      

surdeus

Hi,

sometimes I write documentation like this:

/// Add two numbers.
///
/// TODO: detailed explanation
///
/// **Note:** This function is equivalent to:
/// ```
/// # let left = 4;
/// # let right = 7;
/// # assert_eq!(
/// left + right
/// # , my_crate::add_two_numbers(left, right)
/// # );
/// ```
/// but you do not have to type that weird math symbol.
///
/// # Example
/// ```
/// let x = 1;
/// let y = 2;
///
/// assert_eq!(my_crate::add_two_numbers(x, y), 3);
/// ```
pub fn add_two_numbers(left: i32, right: i32) -> i32 {
    left + right
}

For the first doctest, which renders as a one-liner left + right, I would like to disable line numbers. For the second one (the actual example) the line numbers are fine. Is that possible?

I would also like to keep it tested (so no ```text).

2 posts - 2 participants

Read full topic

🏷️ Rust_feed