多文件切换
点击顶部的 main.rs 和 src/types/operator/builder.rs 切换文件。右侧第一个按钮复制当前文件,第二个按钮展开窗口;展开后按 Esc 返回。
1 2 3 4 5 6 7 8 9 10 11 12 | #[path = "src/types/operator/builder.rs"] mod builder;
use builder::OperatorBuilder;
fn main() { let operator = OperatorBuilder::new("local") .with_timeout(30) .finish();
println!("{}", operator); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | pub struct OperatorBuilder { name: String, timeout: u64, }
impl OperatorBuilder { pub fn new(name: &str) -> Self { Self { name: name.to_owned(), timeout: 10, } }
pub fn with_timeout(mut self, seconds: u64) -> Self { self.timeout = seconds; self }
pub fn finish(self) -> String { format!("{}: timeout={}s", self.name, self.timeout) } } |
单文件展示
单文件也会显示文件名、行号和工具栏。
1 2 3 4 5 | { "name": "blog-code-demo", "theme": "dark", "features": ["file-tabs", "copy", "expand"] } |
文章里怎么写
为相邻代码块填写文件名和相同的组名,就能显示为一组文件标签。
1 2 3 4 5 6 7 | ```rust title="main.rs" group="demo" fn main() {} ```
```rust title="builder.rs" group="demo" pub struct OperatorBuilder; ``` |