diff options
| author | Andrew Hobden <andrew@hoverbear.org> | 2015-03-29 10:03:49 -0700 |
|---|---|---|
| committer | Andrew Hobden <andrew@hoverbear.org> | 2015-03-29 10:03:49 -0700 |
| commit | e489eaa0c5fb4a9d8b716dc3fc63aa653c22f4ec (patch) | |
| tree | 30e2c52f5df39c984db54d0b3c5e2b6c75445453 | |
| parent | b27ba527c5cee06f43967daf3a0dd01a2258a0fa (diff) | |
| download | rust-e489eaa0c5fb4a9d8b716dc3fc63aa653c22f4ec.tar.gz rust-e489eaa0c5fb4a9d8b716dc3fc63aa653c22f4ec.zip | |
Update `std::error` example
To not use `old_io` and `os`, which are deprecated. Since there is no more `MemoryMap` used byte parsing instead to generate the second potential error.
| -rw-r--r-- | src/libcore/error.rs | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/src/libcore/error.rs b/src/libcore/error.rs index 51f3369a75b..5e6acb2142c 100644 --- a/src/libcore/error.rs +++ b/src/libcore/error.rs @@ -48,33 +48,27 @@ //! For example, //! //! ``` -//! # #![feature(os, old_io, old_path)] +//! #![feature(core)] //! use std::error::FromError; -//! use std::old_io::{File, IoError}; -//! use std::os::{MemoryMap, MapError}; -//! use std::old_path::Path; -//! -//! enum MyError { -//! Io(IoError), -//! Map(MapError) +//! use std::{io, str}; +//! use std::fs::File; +//! +//! enum MyError { Io(io::Error), Utf8(str::Utf8Error), } +//! +//! impl FromError<io::Error> for MyError { +//! fn from_error(err: io::Error) -> MyError { MyError::Io(err) } //! } -//! -//! impl FromError<IoError> for MyError { -//! fn from_error(err: IoError) -> MyError { -//! MyError::Io(err) -//! } +//! +//! impl FromError<str::Utf8Error> for MyError { +//! fn from_error(err: str::Utf8Error) -> MyError { MyError::Utf8(err) } //! } -//! -//! impl FromError<MapError> for MyError { -//! fn from_error(err: MapError) -> MyError { -//! MyError::Map(err) -//! } -//! } -//! +//! //! #[allow(unused_variables)] //! fn open_and_map() -> Result<(), MyError> { -//! let f = try!(File::open(&Path::new("foo.txt"))); -//! let m = try!(MemoryMap::new(0, &[])); +//! let b = b"foo.txt"; +//! let s = try!(str::from_utf8(b)); +//! let f = try!(File::open(s)); +//! //! // do something interesting here... //! Ok(()) //! } |
