pub trait TransportFactory: Send + Sync {
// Required methods
fn create_transport(&self, url: &str) -> Result<Box<dyn SmartSubtransport>>;
fn supports_url(&self, url: &str) -> bool;
}Expand description
Factory trait for creating custom git transports
Implementations of this trait can be registered with GitManager to handle
custom URL schemes like gittorrent://, ipfs://, s3://, etc.
§Example
ⓘ
use git2db::transport::TransportFactory;
use git2::transport::SmartSubtransport;
struct MyTransportFactory {
config: MyConfig,
}
impl TransportFactory for MyTransportFactory {
fn create_transport(&self, url: &str) -> anyhow::Result<Box<dyn SmartSubtransport>> {
Ok(Box::new(MyTransport::new(url, &self.config)?))
}
fn supports_url(&self, url: &str) -> bool {
url.starts_with("mytransport://")
}
}Required Methods§
Sourcefn create_transport(&self, url: &str) -> Result<Box<dyn SmartSubtransport>>
fn create_transport(&self, url: &str) -> Result<Box<dyn SmartSubtransport>>
Create a new transport instance for the given URL
This method is called by git2 when a remote operation (clone, fetch, push) needs to communicate with a repository at the given URL.
§Arguments
url- The repository URL (e.g., “gittorrent://abc123/repo”)
§Returns
A boxed SmartSubtransport implementation that handles git protocol operations