lexical_parse_integer/
options.rs

1//! Configuration options for parsing integers.
2
3use lexical_util::options::ParseOptions;
4use lexical_util::result::Result;
5use static_assertions::const_assert;
6
7/// Builder for `Options`.
8#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
9pub struct OptionsBuilder {}
10
11impl OptionsBuilder {
12    /// Create new options builder with default options.
13    #[inline(always)]
14    pub const fn new() -> Self {
15        Self {}
16    }
17
18    // BUILDERS
19
20    /// Check if the builder state is valid.
21    #[inline(always)]
22    pub const fn is_valid(&self) -> bool {
23        true
24    }
25
26    /// Build the Options struct with bounds validation.
27    ///
28    /// # Safety
29    ///
30    /// Safe as long as`is_valid` is true.
31    #[inline(always)]
32    pub const unsafe fn build_unchecked(&self) -> Options {
33        Options {}
34    }
35
36    /// Build the Options struct.
37    #[inline(always)]
38    pub const fn build(&self) -> Result<Options> {
39        // SAFETY: always safe, since it must be valid.
40        Ok(unsafe { self.build_unchecked() })
41    }
42}
43
44impl Default for OptionsBuilder {
45    #[inline(always)]
46    fn default() -> Self {
47        Self::new()
48    }
49}
50
51/// Immutable options to customize writing integers.
52///
53/// # Examples
54///
55/// ```rust
56/// use lexical_parse_integer::options::Options;
57///
58/// # pub fn main() {
59/// let options = Options::builder()
60///     .build()
61///     .unwrap();
62/// # }
63/// ```
64#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
65pub struct Options {}
66
67impl Options {
68    /// Create options with default values.
69    #[inline(always)]
70    pub const fn new() -> Self {
71        Self {}
72    }
73
74    /// Check if the options state is valid.
75    #[inline(always)]
76    pub const fn is_valid(&self) -> bool {
77        true
78    }
79
80    // BUILDERS
81
82    /// Get OptionsBuilder as a static function.
83    #[inline(always)]
84    pub const fn builder() -> OptionsBuilder {
85        OptionsBuilder::new()
86    }
87
88    /// Create OptionsBuilder using existing values.
89    #[inline(always)]
90    pub const fn rebuild(&self) -> OptionsBuilder {
91        OptionsBuilder {}
92    }
93}
94
95impl Default for Options {
96    #[inline(always)]
97    fn default() -> Self {
98        Self::new()
99    }
100}
101
102impl ParseOptions for Options {
103    #[inline(always)]
104    fn is_valid(&self) -> bool {
105        Self::is_valid(self)
106    }
107}
108
109// PRE-DEFINED CONSTANTS
110// ---------------------
111
112/// Standard number format.
113#[rustfmt::skip]
114pub const STANDARD: Options = Options::new();
115const_assert!(STANDARD.is_valid());