Skip to content

Commit e489eaa

Browse files
author
Andrew Hobden
committed
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.
1 parent b27ba52 commit e489eaa

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/libcore/error.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,27 @@
4848
//! For example,
4949
//!
5050
//! ```
51-
//! # #![feature(os, old_io, old_path)]
51+
//! #![feature(core)]
5252
//! use std::error::FromError;
53-
//! use std::old_io::{File, IoError};
54-
//! use std::os::{MemoryMap, MapError};
55-
//! use std::old_path::Path;
56-
//!
57-
//! enum MyError {
58-
//! Io(IoError),
59-
//! Map(MapError)
53+
//! use std::{io, str};
54+
//! use std::fs::File;
55+
//!
56+
//! enum MyError { Io(io::Error), Utf8(str::Utf8Error), }
57+
//!
58+
//! impl FromError<io::Error> for MyError {
59+
//! fn from_error(err: io::Error) -> MyError { MyError::Io(err) }
6060
//! }
61-
//!
62-
//! impl FromError<IoError> for MyError {
63-
//! fn from_error(err: IoError) -> MyError {
64-
//! MyError::Io(err)
65-
//! }
61+
//!
62+
//! impl FromError<str::Utf8Error> for MyError {
63+
//! fn from_error(err: str::Utf8Error) -> MyError { MyError::Utf8(err) }
6664
//! }
67-
//!
68-
//! impl FromError<MapError> for MyError {
69-
//! fn from_error(err: MapError) -> MyError {
70-
//! MyError::Map(err)
71-
//! }
72-
//! }
73-
//!
65+
//!
7466
//! #[allow(unused_variables)]
7567
//! fn open_and_map() -> Result<(), MyError> {
76-
//! let f = try!(File::open(&Path::new("foo.txt")));
77-
//! let m = try!(MemoryMap::new(0, &[]));
68+
//! let b = b"foo.txt";
69+
//! let s = try!(str::from_utf8(b));
70+
//! let f = try!(File::open(s));
71+
//!
7872
//! // do something interesting here...
7973
//! Ok(())
8074
//! }

0 commit comments

Comments
 (0)