Skip to content

Commit 319e353

Browse files
committed
Expose whether URL is special as Url::is_special
1 parent 07b3f3d commit 319e353

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

url/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,27 @@ impl Url {
819819
self.slice(..self.scheme_end)
820820
}
821821

822+
/// Return whether the URL is special (has a special scheme)
823+
///
824+
/// # Examples
825+
///
826+
/// ```
827+
/// use url::Url;
828+
/// # use url::ParseError;
829+
///
830+
/// # fn run() -> Result<(), ParseError> {
831+
/// assert!(Url::parse("http:///tmp/foo")?.is_special());
832+
/// assert!(Url::parse("file:///tmp/foo")?.is_special());
833+
/// assert!(!Url::parse("moz:///tmp/foo")?.is_special());
834+
/// # Ok(())
835+
/// # }
836+
/// # run().unwrap();
837+
/// ```
838+
pub fn is_special(&self) -> bool {
839+
let scheme_type = SchemeType::from(self.scheme());
840+
scheme_type.is_special()
841+
}
842+
822843
/// Return whether the URL has an 'authority',
823844
/// which can contain a username, password, host, and port number.
824845
///

0 commit comments

Comments
 (0)