1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//! Read and write Warcraft III models in text MDL format.
//!
//! Import [`Read`] and [`Write`] as `_` to use `decode_mdl()` and `encode_mdl()`.
//! [`crate::model::Model`] checks an expected version;
//! [`crate::model::DynamicModel`] selects it from the `Version` block.
//! Models also implement `FromStr`: use `source.parse::<Model<V800>>()` or
//! `source.parse::<DynamicModel>()`.
//! Whole-model input requires `Version` first and a `Model` block.
//!
//! ```
//! use wc3::model::{DynamicModel, mdl};
//! use wc3::model::mdl::{Read as _, Write as _};
//!
//! let source = r#"Version { FormatVersion 800, } Model "Example" {}"#;
//! let model = DynamicModel::decode_mdl(source)?;
//! let text = model.encode_mdl()?;
//! let hive = model.encode_mdl_with_dialect(mdl::Dialect::HiveWorkshop)?;
//! assert_eq!(model.version(), 800);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! # Choosing a dialect
//!
//! Readers accept Warcraft III and HiveWorkshop spellings, including mixed input.
//! HiveWorkshop output omits material `SortPrimsNearZ` and layer `WrapWidth`,
//! `WrapHeight`, `Unlit`, `BackFacesForShadows`, and `AmbientOcclusion`.
//! Use Warcraft III output to retain those flags.
//! Output defaults to [`Dialect::Warcraft3`]. Select [`Dialect::HiveWorkshop`] with
//! [`Write::encode_mdl_with_dialect`] or [`Writer::with_dialect`]; the choice
//! applies to all nested records. HiveWorkshop output can represent numeric shader
//! IDs, animations in non-diffuse HD texture slots, and raw geoset selection flags
//! that Warcraft III output cannot express.
//!
//! # Round trips and errors
//!
//! Output preserves represented values, object IDs, and references, while
//! canonicalizing field order and model collections. Comments and source formatting
//! are discarded. Readers reject unknown names, duplicate assignments, incorrect
//! counts, and invalid values. Use [`ReadError::diagnostic`] with the original source
//! for line/column diagnostics.
//!
//! Writers return an error for data that text cannot faithfully represent, such as
//! opaque binary chunks, unknown flag bits, non-UTF-8 fixed text, nonzero text
//! padding. Animation tracks replace their base values in output; reading the
//! output restores those bases to their defaults. NaN payload bits are not
//! preserved. Consequently, an MDX–MDL–MDX round trip need not reproduce the original bytes.
//!
//! Strings are literal: backslashes and line breaks are preserved, and there are
//! no escape sequences. Quotes and NUL cannot be written inside strings. Only
//! `//` comments are accepted. Finite floats round-trip exactly, including negative
//! zero.
//!
//! # Reading or writing part of a file
//!
//! [`Parser::read`] consumes one record from a larger input; `decode_mdl()` requires
//! exactly one value with no trailing input. [`Parser::counted`] reads list entries
//! one at a time. Exhaust the list or call its `finish()` method to validate unread
//! entries and the declared count; dropping it does not validate the remainder.
//!
//! [`Writer`] writes to any standard I/O sink. Errors can leave partial output;
//! use `encode_mdl()` for an owned string before replacing a file.
//!
//! # Standard I/O
//!
//! [`from_reader`] buffers the entire source through EOF and rejects trailing
//! input. [`to_writer`] streams output and checks block balance.
//! Writers do not flush their sinks; I/O failures may leave partial output.
//! Standard I/O adapters and streaming write methods return
//! [`crate::model::IoError`], separating sink/source failures from codec errors.
//! Owned `encode_mdl()` methods return only [`WriteError`].
//!
//! ```
//! use wc3::model::{mdl, Model, V800};
//!
//! let model = "Version { FormatVersion 800, } Model \"Example\" {}".parse::<Model<V800>>()?;
//! let mut output = Vec::new();
//! mdl::to_writer(&mut output, &model)?;
//! let decoded: Model<V800> = mdl::from_reader(output.as_slice())?;
//! assert_eq!(decoded.version(), 800);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
use crateIoError;
pub use enum_names_valid;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ValueEq;
pub use validate_fixed_text;
pub use Writer;
/// Canonical text syntax selected independently of the binary model version.
/// Readers accept both dialects; writers enforce the selected dialect's limits.
// Re-export the bitfield traits for generated code in downstream crates.
pub use ;
use Write as IoWrite;
pub use ;
/// Reads one value directly into its final representation.
/// Writes directly to a sink. Record codecs reject fields they cannot represent,
/// including unknown flag bits and opaque binary padding. Output may be partial
/// on error. Finite floats round-trip exactly; NaNs retain only their NaN class.
/// Stack bitset used by field readers.
/// The supplied bit must identify one field uniquely.
;
pub
pub
pub use ;