Skip to main content

qubit_metadata/schema/
metadata_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//! [`MetadataField`] — one field definition in a metadata schema.
11
12use qubit_datatype::DataType;
13use serde::{
14    Deserialize,
15    Serialize,
16};
17
18/// Definition of one metadata field in a [`crate::MetadataSchema`].
19#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
20pub struct MetadataField {
21    /// Runtime data type of this field.
22    data_type: DataType,
23    /// Whether this field must be present when validating metadata.
24    required: bool,
25}
26
27impl MetadataField {
28    /// Creates a field definition.
29    #[inline]
30    #[must_use]
31    pub fn new(data_type: DataType, required: bool) -> Self {
32        Self { data_type, required }
33    }
34
35    /// Returns the runtime data type of this field.
36    #[inline]
37    #[must_use]
38    pub fn data_type(&self) -> DataType {
39        self.data_type
40    }
41
42    /// Returns `true` when this field is required.
43    #[inline]
44    #[must_use]
45    pub fn is_required(&self) -> bool {
46        self.required
47    }
48}