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::{Deserialize, Serialize};
14
15/// Definition of one metadata field in a [`crate::MetadataSchema`].
16#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
17pub struct MetadataField {
18    /// Runtime data type of this field.
19    data_type: DataType,
20    /// Whether this field must be present when validating metadata.
21    required: bool,
22}
23
24impl MetadataField {
25    /// Creates a field definition.
26    #[inline]
27    #[must_use]
28    pub fn new(data_type: DataType, required: bool) -> Self {
29        Self {
30            data_type,
31            required,
32        }
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}