1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-05-23 19:00:13 +02:00
Alexandre Senges 2023-08-14 16:58:18 +02:00 committed by GitHub
parent 0ac245ee61
commit 7e59a106a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,12 +7,13 @@ all the different possibilities. `std::error::Error` makes this easy.
use std::fs;
use std::io::Read;
use thiserror::Error;
use std::error;
#[derive(Clone, Debug, Eq, Error, PartialEq)]
#[error("Found no username in {0}")]
struct EmptyUsernameError(String);
fn read_username(path: &str) -> Result<String, Box<dyn std::error::Error>> {
fn read_username(path: &str) -> Result<String, Box<dyn error::Error>> {
let mut username = String::new();
fs::File::open(path)?.read_to_string(&mut username)?;
if username.is_empty() {