1
0
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:
Dustin J. Mitchell 2024-09-27 08:39:53 -04:00 committed by GitHub
parent 2713ea3475
commit 9d2ea42fc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,10 +10,10 @@ assist in implementing `From<T>`, `Display`, and the `Error` trait.
```rust,editable,compile_fail ```rust,editable,compile_fail
use std::fs; use std::fs;
use std::io::Read; use std::io::{self, Read};
use thiserror::Error; use thiserror::Error;
#[derive(Error)] #[derive(Debug, Error)]
enum ReadUsernameError { enum ReadUsernameError {
#[error("I/O error: {0}")] #[error("I/O error: {0}")]
IoError(#[from] io::Error), IoError(#[from] io::Error),
@ -23,7 +23,7 @@ enum ReadUsernameError {
fn read_username(path: &str) -> Result<String, ReadUsernameError> { fn read_username(path: &str) -> Result<String, ReadUsernameError> {
let mut username = String::with_capacity(100); 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() { if username.is_empty() {
return Err(ReadUsernameError::EmptyUsername(String::from(path))); return Err(ReadUsernameError::EmptyUsername(String::from(path)));
} }