Is there a way to continue code example from another code block in doc comments?

Hi there! I'm writing documentation of my library and want to give people some code examples (actually, a lot of them). The problem is that sometimes I want to put a code block, then write a couple of sentences about it, and then continue the first code block with another example. Basically I want the second code block to share the scope with the first one, like so:

let a = 32;
// ...

Some text about it.

println!("{}", a);

Right now it's not possible because the second code block uses a variable a that doesn't exist. The only workaround I came up with is to make a single code block and annotate it with more comments, but it doesn't look very good.

Thanks!

Hi, you could duplicate previous blocks and hide them. That would be more work for you but should do what you want.

/// ```
/// # let a = 32;
/// println!("{}", a);
/// ```

This is quite good, thank you!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.