How to do it...

Follow the steps to implement this recipe:

  1. Open the main.rs file in the src directory in your preferred text editor.
  2. Write the code header with the relevant information:
        //-- #########################
//-- Task: Url experiments
//-- Author: Vigneshwer.D
//-- Version: 1.0.0
//-- Date: 04 May 17
//-- #########################
  1. Create the error_chain! macro to define a custom Error and Result type, along with automatic conversions from the standard library error types, after the code header:
        #[macro_use]
extern crate error_chain;
error_chain! {
foreign_links {
UrlParse(url::ParseError);
}
}
  1. Define the run method and the quick_main! macro by copying and pasting the following code snippet with the error_chain! macro:
        extern crate url;
use url::Url;
fn run() -> Result<()> {
let s = "https://github.com/rust-lang/rust/issues?labels=E-easy&state=open";
let parsed = Url::parse(s)?;
println!("The path part of the URL is: {}", parsed.path());
Ok(())
}
quick_main!(run);
  1. Save the file and run the project by running the following command:
      cargo run

We should get the following output on execution of the code:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.220.22