mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-23 08:07:38 +02:00
Fix thiserror slide (#2380)
Fixes #2379. This has `compile_fail` because `thiserror` isn't available from within `mdbook test`.
This commit is contained in:
parent
2713ea3475
commit
9d2ea42fc4
@ -10,10 +10,10 @@ assist in implementing `From<T>`, `Display`, and the `Error` trait.
|
||||
|
||||
```rust,editable,compile_fail
|
||||
use std::fs;
|
||||
use std::io::Read;
|
||||
use std::io::{self, Read};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error)]
|
||||
#[derive(Debug, Error)]
|
||||
enum ReadUsernameError {
|
||||
#[error("I/O error: {0}")]
|
||||
IoError(#[from] io::Error),
|
||||
@ -23,7 +23,7 @@ enum ReadUsernameError {
|
||||
|
||||
fn read_username(path: &str) -> Result<String, ReadUsernameError> {
|
||||
let mut username = String::with_capacity(100);
|
||||
File::open(path)?.read_to_string(&mut username)?;
|
||||
fs::File::open(path)?.read_to_string(&mut username)?;
|
||||
if username.is_empty() {
|
||||
return Err(ReadUsernameError::EmptyUsername(String::from(path)));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user