mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-14 04:58:37 +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:
parent
857511a763
commit
9efad3212f
@ -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.
|
handling in functions, including adding contextual information to your errors.
|
||||||
|
|
||||||
```rust,editable,compile_fail
|
```rust,editable,compile_fail
|
||||||
use std::{fs, io};
|
use anyhow::{bail, Context, Result};
|
||||||
use std::io::Read;
|
use std::{fs, io::Read};
|
||||||
use anyhow::{Context, Result, bail};
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, Error, PartialEq)]
|
#[derive(Clone, Debug, Eq, Error, PartialEq)]
|
||||||
#[error("Found no username in {0}")]
|
#[error("Found no username in {0}")]
|
||||||
@ -25,7 +25,7 @@ fn read_username(path: &str) -> Result<String> {
|
|||||||
.read_to_string(&mut username)
|
.read_to_string(&mut username)
|
||||||
.context("Failed to read")?;
|
.context("Failed to read")?;
|
||||||
if username.is_empty() {
|
if username.is_empty() {
|
||||||
bail!(EmptyUsernameError(path));
|
bail!(EmptyUsernameError(path.to_string()));
|
||||||
}
|
}
|
||||||
Ok(username)
|
Ok(username)
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ impl Iterator for GridIter {
|
|||||||
type Item = (u32, u32);
|
type Item = (u32, u32);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<(u32, u32)> {
|
fn next(&mut self) -> Option<(u32, u32)> {
|
||||||
self.i += 1;
|
|
||||||
if self.i >= self.grid.x_coords.len() {
|
if self.i >= self.grid.x_coords.len() {
|
||||||
self.i = 0;
|
self.i = 0;
|
||||||
self.j += 1;
|
self.j += 1;
|
||||||
@ -42,7 +41,9 @@ impl Iterator for GridIter {
|
|||||||
return None;
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user