Skip to main content

TransportFactory

Trait TransportFactory 

Source
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§

Source

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

Source

fn supports_url(&self, url: &str) -> bool

Check if this factory can handle the given URL

This is checked before calling create_transport to ensure the factory is appropriate for the URL scheme.

§Arguments
  • url - The repository URL to check
§Returns

true if this factory can create transports for this URL, false otherwise

Implementors§