DriverInstaller

Struct DriverInstaller 

Source
pub struct DriverInstaller { /* private fields */ }
Expand description

High-level builder for installing USB drivers.

This provides a fluent interface for configuring and executing driver installation operations. Use one of the constructor methods to create an instance, configure it with the builder methods, then call install to perform the installation.

§Examples

use wdi_rs::{DriverInstaller, DriverType};

DriverInstaller::for_device(0x1234, 0x5678)
    .with_driver_type(DriverType::WinUsb)
    .install()?;

Implementations§

Source§

impl DriverInstaller

Source

pub fn new(device_selector: DeviceSelector) -> Self

Create a new installer with a custom device selector.

For most cases, prefer for_device or for_specific_device.

§Examples
use wdi_rs::{DriverInstaller, DeviceSelector};

let installer = DriverInstaller::new(
    DeviceSelector::First(Box::new(|dev| {
        dev.vid == 0x1234 && dev.desc.as_ref()
            .map_or(false, |m| m.contains("ACME"))
    }))
);
Source

pub fn for_device(vid: u16, pid: u16) -> Self

Create an installer for a device with the specified VID and PID.

If multiple devices match, the first one found will be used.

§Examples
use wdi_rs::DriverInstaller;

let installer = DriverInstaller::for_device(0x1234, 0x5678);
Source

pub fn for_specific_device(device: Device) -> Self

Create an installer for a specific device.

This is useful when you’ve already enumerated devices with create_list and want to install a driver for a specific one.

§Examples
use wdi_rs::{create_list, CreateListOptions, DriverInstaller};

let devices = create_list(CreateListOptions::default()).expect("Failed to list devices");
let device = &devices.get(0).expect("No devices found");
let installer = DriverInstaller::for_specific_device(device.clone());
Source

pub fn with_inf_data(self, data: &[u8], filename: impl Into<String>) -> Self

Set the INF source to embedded data.

The provided data will be written to a temporary file during installation.

§Examples
use wdi_rs::DriverInstaller;

const INF_DATA: &[u8] = include_bytes!("..\\inf\\sample.inf");

let installer = DriverInstaller::for_device(0x1234, 0x5678)
    .with_inf_data(INF_DATA, "my_device.inf");
Source

pub fn with_inf_file(self, path: PathBuf) -> Self

Set the INF source to an external file.

The file must exist and be readable at installation time.

§Examples
use wdi_rs::DriverInstaller;
use std::path::PathBuf;

let installer = DriverInstaller::for_device(0x1234, 0x5678)
    .with_inf_file(PathBuf::from("C:\\drivers\\my_device.inf"));
Source

pub fn with_driver_type(self, driver_type: DriverType) -> Self

Set the driver type to install.

Defaults to DriverType::WinUsb if not specified.

§Examples
use wdi_rs::{DriverInstaller, DriverType};

let installer = DriverInstaller::for_device(0x1234, 0x5678)
    .with_driver_type(DriverType::LibUsb0);
Source

pub fn with_prepare_options(self, opts: PrepareDriverOptions) -> Self

Set custom options for the driver preparation phase.

Note: The external_inf field will be automatically set based on the InfSource and any value you set will be overridden. A warning will be logged if you attempt to set it.

§Examples
use wdi_rs::{DriverInstaller, PrepareDriverOptions};

let mut opts = PrepareDriverOptions::default();
// Configure opts as needed...

let installer = DriverInstaller::for_device(0x1234, 0x5678)
    .with_prepare_options(opts);
Source

pub fn with_install_options(self, opts: InstallDriverOptions) -> Self

Set custom options for the driver installation phase.

§Examples
use wdi_rs::{DriverInstaller, InstallDriverOptions};

let mut opts = InstallDriverOptions::default();
// Configure opts as needed...

let installer = DriverInstaller::for_device(0x1234, 0x5678)
    .with_install_options(opts);
Source

pub fn install(self) -> Result<Device, WdiError>

Perform the driver installation.

This will:

  1. Find the target device (if not already specified)
  2. Check if a driver is already installed
  3. Prepare the driver files
  4. Install the driver

Returns the Device for the device that was installed.

§Errors

Returns an error if:

  • The device cannot be found
  • A non-WinUSB driver is already installed
  • Driver preparation fails
  • Driver installation fails
  • File I/O operations fail
§Examples
use wdi_rs::DriverInstaller;

let device = DriverInstaller::for_device(0x1234, 0x5678)
    .install()?;

println!("Installed driver for device: {}", device);

Trait Implementations§

Source§

impl Debug for DriverInstaller

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.