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
pull/134/head^2
Ovidiu Curcan 3 years ago committed by GitHub
parent acef005895
commit e333d15258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,14 +9,18 @@ below:
## Example
```rust,ignore
std::io::File;
```rust
use std::io;
use std::fs;
# fn main() -> Result<(), Box<dyn std::error::Error>> {
# let arg = "-";
// These must live longer than `readable`, and thus are declared first:
let (mut stdin_read, mut file_read);
// We need to ascribe the type to get dynamic dispatch.
let readable: &mut dyn io::Read = if arg == '-' {
let readable: &mut dyn io::Read = if arg == "-" {
stdin_read = io::stdin();
&mut stdin_read
} else {
@ -25,6 +29,9 @@ let readable: &mut dyn io::Read = if arg == '-' {
};
// Read from `readable` here.
# Ok(())
# }
```
## Motivation

Loading…
Cancel
Save