File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff 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 ///
Original file line number Diff line number Diff line change @@ -157,9 +157,11 @@ impl SchemeType {
157157 pub fn is_file ( & self ) -> bool {
158158 matches ! ( * self , SchemeType :: File )
159159 }
160+ }
160161
161- pub fn from ( s : & str ) -> Self {
162- match s {
162+ impl < T : AsRef < str > > From < T > for SchemeType {
163+ fn from ( s : T ) -> Self {
164+ match s. as_ref ( ) {
163165 "http" | "https" | "ws" | "wss" | "ftp" => SchemeType :: SpecialNotFile ,
164166 "file" => SchemeType :: File ,
165167 _ => SchemeType :: NotSpecial ,
You can’t perform that action at this time.
0 commit comments