Skip to main content

qubit_validator/binding/
dependency_spec.rs

1// =============================================================================
2//    Copyright (c) 2025 - 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8
9//! Dependency slot declarations for prepared validators.
10
11use super::InputType;
12
13/// Describes one ordered dependency slot supplied to a validator.
14///
15/// # Examples
16///
17/// ```
18/// use qubit_validator::{DependencySpec, InputType};
19///
20/// let dependency = DependencySpec::new("credential", InputType::Text, false);
21/// assert_eq!(dependency.name(), "credential");
22/// assert!(!dependency.optional());
23/// ```
24#[derive(Clone, Copy, Debug, Eq, PartialEq)]
25pub struct DependencySpec {
26    /// Logical slot name used in diagnostics.
27    name: &'static str,
28    /// Erased value shape required by the slot.
29    input: InputType,
30    /// Whether the explicit missing marker is accepted.
31    optional: bool,
32}
33
34impl DependencySpec {
35    /// Creates a dependency declaration.
36    ///
37    /// # Parameters
38    ///
39    /// - `name`: non-empty logical slot name used in diagnostics.
40    /// - `input`: erased value shape required by the slot.
41    /// - `optional`: whether an explicit missing value is accepted.
42    ///
43    /// # Returns
44    ///
45    /// Returns a declaration containing the supplied dependency metadata.
46    ///
47    /// # Panics
48    ///
49    /// Panics when `name` is empty.
50    #[must_use]
51    #[inline]
52    pub const fn new(name: &'static str, input: InputType, optional: bool) -> Self {
53        assert!(!name.is_empty(), "dependency name cannot be empty");
54        Self { name, input, optional }
55    }
56
57    /// Returns the logical slot name.
58    #[must_use]
59    #[inline]
60    pub const fn name(self) -> &'static str {
61        self.name
62    }
63
64    /// Returns the required input shape.
65    #[must_use]
66    #[inline]
67    pub const fn input(self) -> InputType {
68        self.input
69    }
70
71    /// Returns whether an explicit missing value is accepted.
72    ///
73    /// # Returns
74    ///
75    /// Returns `true` when the dependency accepts
76    /// [`super::ValidationValue::Missing`].
77    #[must_use]
78    #[inline]
79    pub const fn optional(self) -> bool {
80        self.optional
81    }
82}