Skip to main content

DriverConnector

Trait DriverConnector 

Source
pub trait DriverConnector: Send + Sync {
    type Driver: Driver;
    type Target: Sync;
    type Authentication: Send + 'static;
    type Error: Error + Send + Sync + 'static;

    // Required method
    fn connect<'a>(
        &'a self,
        target: &'a Self::Target,
        authentication: Self::Authentication,
    ) -> impl Future<Output = Result<Self::Driver, Self::Error>> + Send + 'a;
}
Expand description

Constructs and authenticates a provider-specific device driver.

A connector owns the protocol-specific connection process. The caller supplies authentication material it has already resolved; the connector never fetches credentials from a vault or another credential store.

Each provider chooses its own target, authentication, driver, and connection error types. The returned driver remains statically typed.

§Example

use network_device::{Driver, DriverConnector};
use std::convert::Infallible;
use std::future::Future;

struct Target { address: String }
struct Authentication { username: String, password: String }
struct DeviceDriver;
struct Connector;

impl Driver for DeviceDriver {
    type Error = Infallible;
}

impl DriverConnector for Connector {
    type Driver = DeviceDriver;
    type Target = Target;
    type Authentication = Authentication;
    type Error = Infallible;

    fn connect<'a>(
        &'a self,
        target: &'a Self::Target,
        authentication: Self::Authentication,
    ) -> impl Future<Output = Result<Self::Driver, Self::Error>> + Send + 'a {
        async move {
            let _endpoint = &target.address;
            let _username = authentication.username;
            let _password = authentication.password;
            Ok(DeviceDriver)
        }
    }
}

Required Associated Types§

Source

type Driver: Driver

Concrete driver returned after a successful connection.

Source

type Target: Sync

Provider-defined information needed to locate the device.

Source

type Authentication: Send + 'static

Provider-defined, already-resolved authentication material.

Source

type Error: Error + Send + Sync + 'static

Error returned while connecting or authenticating.

Required Methods§

Source

fn connect<'a>( &'a self, target: &'a Self::Target, authentication: Self::Authentication, ) -> impl Future<Output = Result<Self::Driver, Self::Error>> + Send + 'a

Connects to the target and authenticates using the supplied material.

Authentication is passed by value so implementations can consume secrets without requiring a clone or shared ownership wrapper.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§