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, password: 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::from_bytes(value.into()) } } impl TryFrom for Url { type Error = parse::Error; fn try_from(value: String) -> Result { Self::from_bytes(value.as_str().into()) } } impl TryFrom for Url { type Error = parse::Error; fn try_from(value: PathBuf) -> Result { gix_path::into_bstr(value).try_into() } } impl TryFrom<&Path> for Url { type Error = parse::Error; fn try_from(value: &Path) -> Result { 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 { 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::from_bytes(value) } } impl<'a> TryFrom> for Url { type Error = parse::Error; fn try_from(value: std::borrow::Cow<'a, BStr>) -> Result { Self::try_from(&*value) } }