Skip to content

Commit

Permalink
feat: TryFrom<PathBuf> which is useful if urls are obtained from th…
Browse files Browse the repository at this point in the history
…e command-line. (#450)
  • Loading branch information
Byron committed Aug 22, 2022
1 parent 5d6d5ca commit b7a5f7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion git-url/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ doctest = false
serde1 = ["serde", "bstr/serde1"]

[dependencies]
serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"]}
git-features = { version = "^0.22.1", path = "../git-features" }
git-path = { version = "^0.4.0", path = "../git-path" }

serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"]}
thiserror = "1.0.32"
url = "2.1.1"
bstr = { version = "0.2.13", default-features = false, features = ["std"] }
Expand Down
10 changes: 10 additions & 0 deletions git-url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#![deny(rust_2018_idioms, missing_docs)]
#![forbid(unsafe_code)]

use std::path::PathBuf;
use std::{
convert::TryFrom,
fmt::{self},
Expand Down Expand Up @@ -200,6 +201,15 @@ impl TryFrom<String> for Url {
}
}

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<&BStr> for Url {
type Error = parse::Error;

Expand Down

0 comments on commit b7a5f7a

Please sign in to comment.