qubit_metadata/schema/field.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026.
4 * Haixing Hu, Qubit Co. Ltd.
5 *
6 * All rights reserved.
7 *
8 ******************************************************************************/
9//! [`MetadataField`] — one field definition in a metadata schema.
10
11use qubit_common::DataType;
12use serde::{Deserialize, Serialize};
13
14/// Definition of one metadata field in a [`crate::MetadataSchema`].
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16pub struct MetadataField {
17 /// Runtime data type of this field.
18 data_type: DataType,
19 /// Whether this field must be present when validating metadata.
20 required: bool,
21}
22
23impl MetadataField {
24 /// Creates a field definition.
25 #[inline]
26 #[must_use]
27 pub fn new(data_type: DataType, required: bool) -> Self {
28 Self {
29 data_type,
30 required,
31 }
32 }
33
34 /// Returns the runtime data type of this field.
35 #[inline]
36 #[must_use]
37 pub fn data_type(&self) -> DataType {
38 self.data_type
39 }
40
41 /// Returns `true` when this field is required.
42 #[inline]
43 #[must_use]
44 pub fn is_required(&self) -> bool {
45 self.required
46 }
47}