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
impl DriverInstaller
Sourcepub fn new(device_selector: DeviceSelector) -> Self
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"))
}))
);Sourcepub fn for_device(vid: u16, pid: u16) -> Self
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);Sourcepub fn for_specific_device(device: Device) -> Self
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());Sourcepub fn with_inf_data(self, data: &[u8], filename: impl Into<String>) -> Self
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");Sourcepub fn with_inf_file(self, path: PathBuf) -> Self
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"));Sourcepub fn with_driver_type(self, driver_type: DriverType) -> Self
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);Sourcepub fn with_prepare_options(self, opts: PrepareDriverOptions) -> Self
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);Sourcepub fn with_install_options(self, opts: InstallDriverOptions) -> Self
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);Sourcepub fn install(self) -> Result<Device, WdiError>
pub fn install(self) -> Result<Device, WdiError>
Perform the driver installation.
This will:
- Find the target device (if not already specified)
- Check if a driver is already installed
- Prepare the driver files
- 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);