lexical_write_integer/
options.rs

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