pub trait GitProvider<T, E>: Clone + Debug {
// Required method
fn from_git_url(url: &T) -> Result<Self, E>;
}
Expand description
Secondary parser called by GitUrl::provider_info()
to extract Git host provider info from url
// Custom trait example
use git_url_parse::{GitUrl, GitUrlParseError};
use git_url_parse::types::provider::GitProvider;
#[derive(Debug, Clone, PartialEq, Eq)]
struct MyCustomProvider;
impl GitProvider<GitUrl<'_>, GitUrlParseError> for MyCustomProvider {
fn from_git_url(_url: &GitUrl) -> Result<Self, GitUrlParseError> {
// Do your custom parsing here with your GitUrl
Ok(Self)
}
}
let test_url = "git@github.com:tjtelan/git-url-parse-rs.git";
let parsed = GitUrl::parse(test_url).expect("URL parse failed");
// Provide your custom type to `GitUrl::provider_info()`
let provider_info: MyCustomProvider = parsed.provider_info().unwrap();
let expected = MyCustomProvider;
assert_eq!(provider_info, expected)
Required Methods§
Sourcefn from_git_url(url: &T) -> Result<Self, E>
fn from_git_url(url: &T) -> Result<Self, E>
Trait method called by GitUrl::provider_info()
Logic for extracting service level information from a GitUrl
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.