Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 619 Bytes

fragment.zh.md

File metadata and controls

21 lines (15 loc) · 619 Bytes

从 URL 中,删除片段标识符和查询对

[![url-badge]][url] [![cat-net-badge]][cat-net]

解析Url,并url::Position把它切成片,删除不需要的 URL 部分。

extern crate url;

use url::{Url, Position, ParseError};

fn main() -> Result<(), 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(())
}