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
//! Public Rust views over decoded MATLAB MCOS opaque value classes.
//!
//! When [`crate::mat::from_bytes`] reads a MATLAB `datetime`, `duration`, or
//! `categorical` variable, it decodes the hidden `#subsystem#/MCOS` object into
//! its logical components. These structs deserialize from that decoded form, so
//! a field of one of these types in your `#[derive(Deserialize)]` struct picks
//! up the corresponding MATLAB variable directly:
//!
//! ```no_run
//! # #[cfg(feature = "serde")] {
//! use hdf5_pure::mat::{self, MatDatetime, MatCategorical};
//! use serde::Deserialize;
//!
//! #[derive(Deserialize)]
//! struct Log {
//! timestamps: MatDatetime,
//! labels: MatCategorical,
//! }
//!
//! let log: Log = mat::from_bytes(&std::fs::read("log.mat").unwrap()).unwrap();
//! let epoch_ns = log.timestamps.nanoseconds();
//! let resolved = log.labels.labels(); // Vec<Option<String>>
//! # let _ = (epoch_ns, resolved);
//! # }
//! ```
//!
//! The representations are lossless: the raw MATLAB storage (milliseconds since
//! the Unix epoch, category codes, …) is preserved, and helper methods offer the
//! common derived views.
use Deserialize;
/// A decoded MATLAB `datetime` array.
///
/// MATLAB stores datetimes as milliseconds since the Unix epoch (1970-01-01
/// UTC, with no time-zone offset folded in) using a two-part "double-double"
/// value: the true millisecond count of each element is [`millis_utc`] `+`
/// [`sub_ms`]. [`millis_utc`] already carries sub-millisecond precision in its
/// fractional part; [`sub_ms`] is the residual below that part's `f64` ULP.
/// Both are preserved losslessly, and this split has been validated against
/// real MATLAB output. [`tz`] and [`fmt`] are display metadata and do not shift
/// the stored instant.
///
/// `NaT` (not-a-time) elements appear as `NaN` in [`millis_utc`].
///
/// [`millis_utc`]: MatDatetime::millis_utc
/// [`sub_ms`]: MatDatetime::sub_ms
/// [`tz`]: MatDatetime::tz
/// [`fmt`]: MatDatetime::fmt
/// A decoded MATLAB `duration` array.
///
/// MATLAB stores durations as milliseconds. [`millis`] is preserved losslessly;
/// [`fmt`] is the display unit and does not change the stored value.
///
/// [`millis`]: MatDuration::millis
/// [`fmt`]: MatDuration::fmt
/// A decoded MATLAB `categorical` array.
///
/// [`codes`] holds the 1-based category index of each element (`0` is
/// `<undefined>`); [`categories`] is the category-name pool. [`is_ordinal`] and
/// [`is_protected`] mirror the MATLAB flags.
///
/// [`codes`]: MatCategorical::codes
/// [`categories`]: MatCategorical::categories
/// [`is_ordinal`]: MatCategorical::is_ordinal
/// [`is_protected`]: MatCategorical::is_protected
/// A decoded MATLAB enumeration array.
///
/// MATLAB enumerations (`classdef … enumeration … end`) store each element as a
/// named member of an enumeration class. [`class_name`] is the fully qualified
/// class (e.g. `"MyPkg.Color"`, or a bare `"Weekday"` for an unpackaged class);
/// [`names`] is the member name of each element (e.g. `"Red"`) in row-major
/// order.
///
/// The member name is the enumeration's identity, so it is what this view
/// surfaces. The underlying value backing each member (the `double` / integer
/// the member maps to) is not decoded.
///
/// [`class_name`]: MatEnum::class_name
/// [`names`]: MatEnum::names