Skip to content

Commit e333d15

Browse files
author
Ovidiu Curcan
authored
Fix on-stack dispatch example (#137)
A `char` can't be used as a path. You already use the correct `"-"` in the "Disadvantages" example. Remove `ignore` for the example block
1 parent acef005 commit e333d15

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

idioms/on-stack-dyn-dispatch.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ below:
99

1010
## Example
1111

12-
```rust,ignore
13-
std::io::File;
12+
```rust
13+
use std::io;
14+
use std::fs;
15+
16+
# fn main() -> Result<(), Box<dyn std::error::Error>> {
17+
# let arg = "-";
1418

1519
// These must live longer than `readable`, and thus are declared first:
1620
let (mut stdin_read, mut file_read);
1721

1822
// We need to ascribe the type to get dynamic dispatch.
19-
let readable: &mut dyn io::Read = if arg == '-' {
23+
let readable: &mut dyn io::Read = if arg == "-" {
2024
stdin_read = io::stdin();
2125
&mut stdin_read
2226
} else {
@@ -25,6 +29,9 @@ let readable: &mut dyn io::Read = if arg == '-' {
2529
};
2630

2731
// Read from `readable` here.
32+
33+
# Ok(())
34+
# }
2835
```
2936

3037
## Motivation

0 commit comments

Comments
 (0)