Merge pull request #55 from budziq/master

implemented "Remove fragment identifiers and query pairs from a URL"
This commit is contained in:
David Tolnay 2017-05-08 14:30:04 -07:00 committed by GitHub
commit 39918a90a2

View file

@ -201,7 +201,24 @@ fn main() {
<a name="ex-url-rm-frag"></a> <a name="ex-url-rm-frag"></a>
## Remove fragment identifiers and query pairs from a URL ## Remove fragment identifiers and query pairs from a URL
[Write me!](https://github.com/brson/rust-cookbook/issues/37) Once [`Url`] is parsed it can be sliced with [`url::Position`] to strip unneded URL parts.
```rust
extern crate url;
use url::{Url, Position};
fn run() -> Result<(), url::ParseError> {
let parsed = Url::parse("https://github.com/rust-lang/rust/issues?labels=E-easy&state=open")?;
let cleaned: &str = &parsed[..Position::AfterPath];
println!("cleaned: {}", cleaned);
Ok(())
}
fn main() {
run().unwrap();
}
```
[ex-url-serialize]: #ex-url-serialize [ex-url-serialize]: #ex-url-serialize
<a name="ex-url-serialize"></a> <a name="ex-url-serialize"></a>
@ -235,5 +252,6 @@ fn main() {
[`Url`]: https://docs.rs/url/1.*/url/struct.Url.html [`Url`]: https://docs.rs/url/1.*/url/struct.Url.html
[`parse`]: https://docs.rs/url/1.*/url/struct.Url.html#method.parse [`parse`]: https://docs.rs/url/1.*/url/struct.Url.html#method.parse
[`url::Position`]: https://docs.rs/url/*/url/enum.Position.html
[`origin`]: https://docs.rs/url/1.*/url/struct.Url.html#method.origin [`origin`]: https://docs.rs/url/1.*/url/struct.Url.html#method.origin
[`join`]: https://docs.rs/url/1.*/url/struct.Url.html#method.join [`join`]: https://docs.rs/url/1.*/url/struct.Url.html#method.join