Skip to content

Commit

Permalink
doc: improve example
Browse files Browse the repository at this point in the history
  • Loading branch information
tshepang committed Mar 30, 2017
1 parent 37a253c commit 79bc73b
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,41 @@
//!
//! # Usage
//!
//! The following should open the given URL in a web browser
//!
//! ```test_harness,no_run
//! extern crate open;
//!
//! # #[test]
//! # fn doit() {
//! open::that("/path/to/file/with.fancy-extension");
//! if open::that("https://rust-lang.org").is_ok() {
//! println!("Look at your browser !");
//! }
//! open::that("http://rust-lang.org").unwrap();
//! # }
//! ```
//!
//! # Notes
//!
//! As an operating system program is used, chances are that the open operation fails.
//! Therfore, you are advised to at least check the result with `.is_err()` and
//! behave accordingly, e.g. by letting the user know what you tried to open, and failed.
//!
//! ```
//! # fn doit() {
//! match open::that("http://rust-lang.org") {
//! Ok(exit_status) => {
//! if exit_status.success() {
//! println!("Look at your browser !");
//! } else {
//! if let Some(code) = exit_status.code() {
//! println!("Command returned non-zero exit status {}!", code);
//! } else {
//! println!("Command returned with unknown exit status!");
//! }
//! }
//! }
//! Err(why) => println!("Failure to execute command: {}", why),
//! }
//! # }
//! ```
use std::io;
use std::process::{Command, ExitStatus};
use std::ffi::OsStr;
Expand Down

0 comments on commit 79bc73b

Please sign in to comment.