diff options
| author | bors <bors@rust-lang.org> | 2019-08-21 11:01:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-08-21 11:01:11 +0000 |
| commit | f9987c8bed3fb7e376c2c21fa2d2c3731e69e2df (patch) | |
| tree | 0c843e2c47caea952baaab255809b3a8d4d9f44b /exercises | |
| parent | c5bb32253b145b96c2f3049c2f0644f13d921290 (diff) | |
| parent | 8109cbad97e33949391cc36739121669df90e964 (diff) | |
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: https://github.com/rust-lang/rustlings/issues/211
Diffstat (limited to 'exercises')
| -rw-r--r-- | exercises/error_handling/errorsn.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/exercises/error_handling/errorsn.rs b/exercises/error_handling/errorsn.rs index ea1905e..c2b16ce 100644 --- a/exercises/error_handling/errorsn.rs +++ b/exercises/error_handling/errorsn.rs @@ -20,7 +20,7 @@ use std::fmt; use std::io; // PositiveNonzeroInteger is a struct defined below the tests. -fn read_and_validate(b: &mut io::BufRead) -> Result<PositiveNonzeroInteger, ???> { +fn read_and_validate(b: &mut dyn io::BufRead) -> Result<PositiveNonzeroInteger, ???> { let mut line = String::new(); b.read_line(&mut line); let num: i64 = line.trim().parse(); @@ -29,7 +29,7 @@ fn read_and_validate(b: &mut io::BufRead) -> Result<PositiveNonzeroInteger, ???> } // This is a test helper function that turns a &str into a BufReader. -fn test_with_str(s: &str) -> Result<PositiveNonzeroInteger, Box<error::Error>> { +fn test_with_str(s: &str) -> Result<PositiveNonzeroInteger, Box<dyn error::Error>> { let mut b = io::BufReader::new(s.as_bytes()); read_and_validate(&mut b) } @@ -98,7 +98,7 @@ enum CreationError { impl fmt::Display for CreationError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str((self as &error::Error).description()) + f.write_str((self as &dyn error::Error).description()) } } @@ -190,7 +190,7 @@ impl error::Error for CreationError { // Another hint: under the hood, the `?` operator calls `From::from` -// on the error value to convert it to a boxed trait object, a Box<error::Error>, +// on the error value to convert it to a boxed trait object, a Box<dyn error::Error>, // which is polymorphic-- that means that lots of different kinds of errors // can be returned from the same function because all errors act the same // since they all implement the `error::Error` trait. |
