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 {
33 data_type,
34 required,
35 }
36 }
37
38 /// Returns the runtime data type of this field.
39 #[inline]
40 #[must_use]
41 pub fn data_type(&self) -> DataType {
42 self.data_type
43 }
44
45 /// Returns `true` when this field is required.
46 #[inline]
47 #[must_use]
48 pub fn is_required(&self) -> bool {
49 self.required
50 }
51}