Skip to content

Commit

Permalink
Update std::error example
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Andrew Hobden committed Mar 29, 2015
1 parent b27ba52 commit e489eaa
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/libcore/error.rs
Expand Up @@ -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(())
//! }
Expand Down

0 comments on commit e489eaa

Please sign in to comment.