Skip to content

Commit f9987c8

Browse files
committed
Auto merge of #212 - sosnowski:fix/add-dyn-trait, r=komaeda
fix(errorsn.rs) Update the deprecated syntax by adding dyn to trait o… fix(errorsn.rs) Update the deprecated syntax by adding dyn to trait objects. closes #211 Related issue: #211
2 parents c5bb322 + 8109cba commit f9987c8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

exercises/error_handling/errorsn.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::fmt;
2020
use std::io;
2121

2222
// PositiveNonzeroInteger is a struct defined below the tests.
23-
fn read_and_validate(b: &mut io::BufRead) -> Result<PositiveNonzeroInteger, ???> {
23+
fn read_and_validate(b: &mut dyn io::BufRead) -> Result<PositiveNonzeroInteger, ???> {
2424
let mut line = String::new();
2525
b.read_line(&mut line);
2626
let num: i64 = line.trim().parse();
@@ -29,7 +29,7 @@ fn read_and_validate(b: &mut io::BufRead) -> Result<PositiveNonzeroInteger, ???>
2929
}
3030

3131
// This is a test helper function that turns a &str into a BufReader.
32-
fn test_with_str(s: &str) -> Result<PositiveNonzeroInteger, Box<error::Error>> {
32+
fn test_with_str(s: &str) -> Result<PositiveNonzeroInteger, Box<dyn error::Error>> {
3333
let mut b = io::BufReader::new(s.as_bytes());
3434
read_and_validate(&mut b)
3535
}
@@ -98,7 +98,7 @@ enum CreationError {
9898

9999
impl fmt::Display for CreationError {
100100
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
101-
f.write_str((self as &error::Error).description())
101+
f.write_str((self as &dyn error::Error).description())
102102
}
103103
}
104104

@@ -190,7 +190,7 @@ impl error::Error for CreationError {
190190

191191

192192
// Another hint: under the hood, the `?` operator calls `From::from`
193-
// on the error value to convert it to a boxed trait object, a Box<error::Error>,
193+
// on the error value to convert it to a boxed trait object, a Box<dyn error::Error>,
194194
// which is polymorphic-- that means that lots of different kinds of errors
195195
// can be returned from the same function because all errors act the same
196196
// since they all implement the `error::Error` trait.

0 commit comments

Comments
 (0)