1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-15 06:20:32 +02:00

More minor fixes (#1561)

- Fix compile errors and warnings in error handling example
- Tweak iteration example so that it correctly visits the first grid
coordinate
This commit is contained in:
Marshall Pierce 2023-12-06 10:53:06 -07:00 committed by GitHub
parent 857511a763
commit 9efad3212f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -10,9 +10,9 @@ create custom error types that implement `From<T>`. `anyhow` helps with error
handling in functions, including adding contextual information to your errors.
```rust,editable,compile_fail
use std::{fs, io};
use std::io::Read;
use anyhow::{Context, Result, bail};
use anyhow::{bail, Context, Result};
use std::{fs, io::Read};
use thiserror::Error;
#[derive(Clone, Debug, Eq, Error, PartialEq)]
#[error("Found no username in {0}")]
@ -25,7 +25,7 @@ fn read_username(path: &str) -> Result<String> {
.read_to_string(&mut username)
.context("Failed to read")?;
if username.is_empty() {
bail!(EmptyUsernameError(path));
bail!(EmptyUsernameError(path.to_string()));
}
Ok(username)
}

View File

@ -34,7 +34,6 @@ impl Iterator for GridIter {
type Item = (u32, u32);
fn next(&mut self) -> Option<(u32, u32)> {
self.i += 1;
if self.i >= self.grid.x_coords.len() {
self.i = 0;
self.j += 1;
@ -42,7 +41,9 @@ impl Iterator for GridIter {
return None;
}
}
Some((self.grid.x_coords[self.i], self.grid.y_coords[self.j]))
let res = Some((self.grid.x_coords[self.i], self.grid.y_coords[self.j]));
self.i += 1;
res
}
}