2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use std::{error::Error, fmt};
24 use crate::ValidationError;
26 /* Helper code for validation */
27 impl Error for ValidationError {}
28 impl fmt::Display for ValidationError {
29 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30 write!(f, "{}", self.msg)
36 // A helper to define a function returning a constant value and an equal function as a Rust path */
37 pub struct U64<const U: u64>;
38 impl<const U: u64> U64<U> {
39 pub const fn value() -> u64 {
42 pub fn is_equal(v: &u64) -> bool {
47 // A helper to define constant value as a Rust path */
48 pub struct Bool<const U: bool>;
49 impl<const U: bool> Bool<U> {
50 pub const fn value() -> bool {
55 // A helper used to decide if a bool value should be skipped
56 pub fn if_true(v: &bool) -> bool {
60 /* Helper to decide if a value has a default value, as defined by Default trait */
61 pub fn is_default<T: Default + PartialEq>(t: &T) -> bool {
65 pub const OVERRIDE_TAG: &str = "!override";
67 pub fn is_overriding(m: &serde_yaml::Mapping, key: &str) -> bool{
68 if let Some(serde_yaml::Value::Tagged(vvv)) = m.get(key) {
69 return vvv.tag == OVERRIDE_TAG;