pico_driver/
resolution.rs

1use pico_common::Driver;
2use std::{env::current_exe, path::PathBuf};
3
4/// Instructs the loader where to load drivers from
5#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
6pub enum Resolution {
7    /// Searches for drivers using the OS default path resolution
8    Default,
9    /// Searches for drivers in the application root directory
10    AppRoot,
11    /// Searches for drivers at a specific path
12    Custom(PathBuf),
13}
14
15impl Resolution {
16    /// Get the expected path for a driver for this resolution
17    pub fn get_path(&self, driver: Driver) -> PathBuf {
18        let binary_name = driver.get_binary_name();
19
20        match self {
21            Resolution::Default => PathBuf::from(binary_name),
22            Resolution::AppRoot => current_exe()
23                .expect("current_exe path could not be found")
24                .parent()
25                .expect("current_exe path does not have parent")
26                .join(binary_name),
27            Resolution::Custom(path) => path.join(binary_name),
28        }
29    }
30}
31
32impl Default for Resolution {
33    fn default() -> Self {
34        Resolution::Default
35    }
36}