How to mark a 'not part of example' branch?
⚓ Rust 📅 2025-08-23 👤 surdeus 👁️ 10Hi,
I have a function returning some enum with a documentaion and an example:
/// Some function
///
/// # Example
/// ```
/// // some code ...
///
/// let SomeEnum::SomeVariant(...) = some_function() else { unreachable!() };
///
/// // more code...
/// ```
fn some_function() -> SomeEnum {
todo!()
}
My question is: What to put inside the else branch (or analogous places in other branching constructs that require exhaustiveness) to indicate that it is not a part of the example?
If SomeEnum was a Result, I would just use an unwrap() or ? (and not bother with let ... else), but for my types these are not available by default and it does not make sense to add them (e.g. unwrap()-like method) just to be used in examples.
Currently I am using unreachable!() (as shown), but I do not want to make an impression that this usage is intended for my function(s).
Is there something better? Or is this ok?
1 post - 1 participant
🏷️ Rust_feed