summaryrefslogtreecommitdiffstats
path: root/vendor/gix-url/src/impls.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gix-url/src/impls.rs')
-rw-r--r--vendor/gix-url/src/impls.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/vendor/gix-url/src/impls.rs b/vendor/gix-url/src/impls.rs
new file mode 100644
index 000000000..d3c578088
--- /dev/null
+++ b/vendor/gix-url/src/impls.rs
@@ -0,0 +1,79 @@
+use std::{
+ convert::TryFrom,
+ path::{Path, PathBuf},
+};
+
+use bstr::BStr;
+
+use crate::{parse, Scheme, Url};
+
+impl Default for Url {
+ fn default() -> Self {
+ Url {
+ serialize_alternative_form: false,
+ scheme: Scheme::Ssh,
+ user: None,
+ host: None,
+ port: None,
+ path: bstr::BString::default(),
+ }
+ }
+}
+
+impl TryFrom<&str> for Url {
+ type Error = parse::Error;
+
+ fn try_from(value: &str) -> Result<Self, Self::Error> {
+ Self::from_bytes(value.into())
+ }
+}
+
+impl TryFrom<String> for Url {
+ type Error = parse::Error;
+
+ fn try_from(value: String) -> Result<Self, Self::Error> {
+ Self::from_bytes(value.as_str().into())
+ }
+}
+
+impl TryFrom<PathBuf> for Url {
+ type Error = parse::Error;
+
+ fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
+ gix_path::into_bstr(value).try_into()
+ }
+}
+
+impl TryFrom<&Path> for Url {
+ type Error = parse::Error;
+
+ fn try_from(value: &Path) -> Result<Self, Self::Error> {
+ gix_path::into_bstr(value).try_into()
+ }
+}
+
+impl TryFrom<&std::ffi::OsStr> for Url {
+ type Error = parse::Error;
+
+ fn try_from(value: &std::ffi::OsStr) -> Result<Self, Self::Error> {
+ gix_path::os_str_into_bstr(value)
+ .expect("no illformed UTF-8 on Windows")
+ .try_into()
+ }
+}
+
+impl TryFrom<&BStr> for Url {
+ type Error = parse::Error;
+
+ fn try_from(value: &BStr) -> Result<Self, Self::Error> {
+ Self::from_bytes(value)
+ }
+}
+
+impl<'a> TryFrom<std::borrow::Cow<'a, BStr>> for Url {
+ type Error = parse::Error;
+
+ fn try_from(value: std::borrow::Cow<'a, BStr>) -> Result<Self, Self::Error> {
+ Self::try_from(&*value)
+ }
+}