File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -819,6 +819,27 @@ impl Url {
819
819
self . slice ( ..self . scheme_end )
820
820
}
821
821
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
+
822
843
/// Return whether the URL has an 'authority',
823
844
/// which can contain a username, password, host, and port number.
824
845
///
Original file line number Diff line number Diff line change @@ -157,9 +157,11 @@ impl SchemeType {
157
157
pub fn is_file ( & self ) -> bool {
158
158
matches ! ( * self , SchemeType :: File )
159
159
}
160
+ }
160
161
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 ( ) {
163
165
"http" | "https" | "ws" | "wss" | "ftp" => SchemeType :: SpecialNotFile ,
164
166
"file" => SchemeType :: File ,
165
167
_ => SchemeType :: NotSpecial ,
You can’t perform that action at this time.
0 commit comments