use std::{convert::TryFrom, path::PathBuf}; use bstr::BStr; use crate::{parse, Scheme, Url}; impl Default for Url { fn default() -> Self { Url { 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> { use std::convert::TryInto; git_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> { use std::convert::TryInto; git_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) }}
use std::{convert::TryFrom, path::PathBuf};
use bstr::BStr;
use crate::{parse, Scheme, Url};
impl Default for Url {
fn default() -> Self {
Url {
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> {
use std::convert::TryInto;
git_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> {
use std::convert::TryInto;
git_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)
}
}