qubit_validator/argument/validation_argument.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//! Domain-neutral validator parameter values.
10
11use std::fmt;
12
13/// One statically typed validator parameter value.
14///
15/// # Type Parameters
16///
17/// - `'a`: Lifetime of any borrowed string or slice carried by the value.
18///
19/// # Examples
20///
21/// ```
22/// use qubit_validator::ValidationArgument;
23///
24/// let argument = ValidationArgument::String("admin");
25/// assert_eq!(argument, ValidationArgument::String("admin"));
26/// ```
27#[derive(Clone, Copy, Eq, PartialEq)]
28#[non_exhaustive]
29pub enum ValidationArgument<'a> {
30 /// A Boolean value.
31 Bool(
32 /// The supplied Boolean value.
33 bool,
34 ),
35 /// A signed integer value.
36 Integer(
37 /// The supplied signed integer value.
38 i128,
39 ),
40 /// An unsigned integer value.
41 Unsigned(
42 /// The supplied unsigned integer value.
43 u128,
44 ),
45 /// A string value.
46 String(
47 /// The supplied borrowed string.
48 &'a str,
49 ),
50 /// A Boolean list.
51 BoolList(
52 /// The supplied borrowed Boolean slice.
53 &'a [bool],
54 ),
55 /// A signed integer list.
56 IntegerList(
57 /// The supplied borrowed signed integer slice.
58 &'a [i128],
59 ),
60 /// An unsigned integer list.
61 UnsignedList(
62 /// The supplied borrowed unsigned integer slice.
63 &'a [u128],
64 ),
65 /// A string list.
66 StringList(
67 /// The supplied borrowed slice of borrowed strings.
68 &'a [&'a str],
69 ),
70}
71
72impl fmt::Debug for ValidationArgument<'_> {
73 /// Redacts scalar contents and reports only collection lengths.
74 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
75 match self {
76 Self::Bool(_) => formatter.write_str("Bool(<redacted>)"),
77 Self::Integer(_) => formatter.write_str("Integer(<redacted>)"),
78 Self::Unsigned(_) => formatter.write_str("Unsigned(<redacted>)"),
79 Self::String(_) => formatter.write_str("String(<redacted>)"),
80 Self::BoolList(values) => formatter.debug_struct("BoolList").field("len", &values.len()).finish(),
81 Self::IntegerList(values) => formatter
82 .debug_struct("IntegerList")
83 .field("len", &values.len())
84 .finish(),
85 Self::UnsignedList(values) => formatter
86 .debug_struct("UnsignedList")
87 .field("len", &values.len())
88 .finish(),
89 Self::StringList(values) => formatter
90 .debug_struct("StringList")
91 .field("len", &values.len())
92 .finish(),
93 }
94 }
95}