1use std::{
2 str::FromStr,
3 time::Duration,
4};
5
6#[derive(Debug, Clone, Copy)]
7#[non_exhaustive]
8pub enum Strategy {
9 Iokit,
11 Diskutil,
14}
15
16#[derive(Debug, Clone, Copy)]
17pub struct ReadOptions {
18 pub(crate) remote_stats: bool,
19 pub(crate) strategy: Option<Strategy>,
20 pub(crate) stats_timeout: Option<Duration>,
21}
22impl Default for ReadOptions {
23 fn default() -> Self {
24 Self {
25 remote_stats: true,
26 strategy: None,
27 stats_timeout: Some(Duration::from_millis(50)),
28 }
29 }
30}
31impl ReadOptions {
32 pub fn remote_stats(
33 mut self,
34 v: bool,
35 ) -> Self {
36 self.remote_stats = v;
37 self
38 }
39 pub fn strategy(
40 mut self,
41 v: Strategy,
42 ) -> Self {
43 self.strategy = Some(v);
44 self
45 }
46 pub fn stats_timeout(
49 mut self,
50 v: Option<Duration>,
51 ) -> Self {
52 self.stats_timeout = v;
53 self
54 }
55}
56
57#[derive(Debug, Clone, Copy, PartialEq, Eq)]
58pub struct ParseStrategyError;
59impl FromStr for Strategy {
60 type Err = ParseStrategyError;
61 fn from_str(s: &str) -> Result<Self, Self::Err> {
62 match s {
63 "iokit" => Ok(Self::Iokit),
64 "diskutil" => Ok(Self::Diskutil),
65 _ => Err(ParseStrategyError),
66 }
67 }
68}