xsd_parser/models/data/
mod.rs

1//! Rust-oriented data type representations for code generation.
2//!
3//! This module defines the full set of intermediate structures used to represent
4//! resolved and Rust-specific data types, derived from interpreted and optimized
5//! XML schemas meta types.
6//!
7//! These types abstract the XML schema constructs into idiomatic Rust equivalents
8//! like structs, enums, options, and vectors, and form the backbone of the code
9//! generation phase.
10
11mod build_in;
12mod complex;
13mod constrains;
14mod custom;
15mod dynamic;
16mod enumeration;
17mod occurs;
18mod path_data;
19mod reference;
20mod simple;
21mod tag_name;
22mod type_;
23mod types;
24mod union;
25
26use std::ops::Bound;
27
28use crate::models::meta::Constrains;
29
30pub use self::build_in::BuildInData;
31pub use self::complex::{
32    ComplexBase, ComplexData, ComplexDataAttribute, ComplexDataContent, ComplexDataElement,
33    ComplexDataElementOrigin, ComplexDataEnum, ComplexDataStruct, ComplexFlags, StructMode,
34};
35pub use self::constrains::ConstrainsData;
36pub use self::custom::CustomData;
37pub use self::dynamic::{DerivedType, DynamicData};
38pub use self::enumeration::{EnumerationData, EnumerationTypeVariant};
39pub use self::occurs::Occurs;
40pub use self::path_data::PathData;
41pub use self::reference::ReferenceData;
42pub use self::simple::SimpleData;
43pub use self::tag_name::TagName;
44pub use self::type_::{DataType, DataTypeVariant};
45pub use self::types::DataTypes;
46pub use self::union::{UnionData, UnionTypeVariant};
47
48/// A generic configuration value wrapper that supports different merging strategies.
49///
50/// This enum is used to represent configuration fields that may either use default values,
51/// extend existing ones, or completely overwrite them. It provides a flexible mechanism
52/// for combining configurations from multiple sources.
53#[derive(Default, Debug)]
54pub enum ConfigValue<T> {
55    /// Uses the default behavior or value.
56    #[default]
57    Default,
58
59    /// Appends or merges the provided value with existing data.
60    Extend(T),
61
62    /// Replaces any existing data with the provided value.
63    Overwrite(T),
64}
65
66impl Constrains {
67    /// Returns `true` if this simple type needs value validation, `false` otherwise.
68    #[must_use]
69    pub fn need_value_validation(&self) -> bool {
70        self.range.start != Bound::Unbounded
71            || self.range.end != Bound::Unbounded
72            || self.min_length.is_some()
73            || self.max_length.is_some()
74    }
75
76    /// Returns `true` if this simple type needs string validation, `false` otherwise.
77    #[must_use]
78    pub fn need_string_validation(&self) -> bool {
79        !self.patterns.is_empty() || self.total_digits.is_some() || self.fraction_digits.is_some()
80    }
81}