qubit_config/field/config_field.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_name_builder::ConfigFieldNameBuilder;
16
17/// Field-level read declaration for [`crate::ConfigReader::read`].
18///
19#[derive(Debug, Clone, PartialEq)]
20pub struct ConfigField<T> {
21 /// The primary field name.
22 pub(crate) name: String,
23 /// The fallback aliases.
24 pub(crate) aliases: Vec<String>,
25 /// The default value.
26 pub(crate) default: Option<T>,
27 /// The read options.
28 pub(crate) read_options: Option<ConfigReadOptions>,
29}
30
31impl<T> ConfigField<T> {
32 /// Starts building a field declaration.
33 ///
34 /// # Returns
35 ///
36 /// A builder requiring a primary field name before `build` is available.
37 pub fn builder() -> ConfigFieldNameBuilder<T> {
38 ConfigFieldNameBuilder {
39 aliases: Vec::new(),
40 default: None,
41 read_options: None,
42 marker: PhantomData,
43 }
44 }
45}