Skip to main content

qubit_config/field/
config_field_name_builder.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10
11use std::marker::PhantomData;
12
13use crate::options::ConfigReadOptions;
14
15use super::config_field_builder::ConfigFieldBuilder;
16
17/// Builder state before the field name is provided.
18///
19pub struct ConfigFieldNameBuilder<T> {
20    /// The fallback aliases.
21    pub(crate) aliases: Vec<String>,
22    /// The default value.
23    pub(crate) default: Option<T>,
24    /// The read options.
25    pub(crate) read_options: Option<ConfigReadOptions>,
26    /// The type marker.
27    pub(crate) marker: PhantomData<T>,
28}
29
30impl<T> ConfigFieldNameBuilder<T> {
31    /// Sets the primary field name and unlocks [`super::ConfigFieldBuilder::build`].
32    ///
33    /// # Parameters
34    ///
35    /// * `name` - Primary configuration key.
36    ///
37    /// # Returns
38    ///
39    /// Builder state with a primary name.
40    pub fn name(self, name: &str) -> ConfigFieldBuilder<T> {
41        ConfigFieldBuilder {
42            name: name.to_string(),
43            aliases: self.aliases,
44            default: self.default,
45            read_options: self.read_options,
46        }
47    }
48}