I've been using Visual Studio Code with the Rust Analyzer for years now and it's nearly flawless except for maintaining example code within rustdoc snippets. Here's an example:
/// StaticFunction implodes the universe into a conveniently sized travel lozenge
///
/// ```
/// use crate::ImportantThing;
/// ImportantThing::StaticFunction();
/// ```
fn StaticFunction() {
todo!()
}
What I find problematic is during refactoring, I may have renamed the function or imports, or both and so I need to go back and edit without the convenience of code completion, and the rest.
I was wondering how others handle this. In an ideal world I could reference some test code that would get imported during the doc building phase, maybe with a macro named include_function!
. Something like this:
/// StaticFunction implodes the universe into a conveniently sized travel lozenge
///
/// ```
/// include_function!(test::test_static_function)
/// ```
fn StaticFunction() {
todo!()
}
#[cfg(test)
mod test {
#[test]
fn test_static_function() {
use super::StaticFunction;
StaticFunction();
}
}
Thoughts? Any ideas on how to maintain rustdoc example code is welcome.