cadmpeg_core/decode/
depth.rs1use std::fmt;
5
6#[cfg(feature = "schema")]
7use schemars::JsonSchema;
8use serde::{Deserialize, Serialize};
9
10#[derive(
16 Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize,
17)]
18#[cfg_attr(feature = "schema", derive(JsonSchema))]
19#[serde(rename_all = "snake_case")]
20pub enum DecodeDepth {
21 Container,
24 Geometry,
29 #[default]
31 Full,
32}
33
34impl DecodeDepth {
35 #[must_use]
37 pub const fn as_str(self) -> &'static str {
38 match self {
39 Self::Container => "container",
40 Self::Geometry => "geometry",
41 Self::Full => "full",
42 }
43 }
44}
45
46impl fmt::Display for DecodeDepth {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 f.pad(self.as_str())
49 }
50}
51
52#[cfg(test)]
53mod tests {
54 use super::DecodeDepth;
55
56 #[test]
57 fn depths_order_by_what_they_transfer() {
58 assert!(DecodeDepth::Container < DecodeDepth::Geometry);
59 assert!(DecodeDepth::Geometry < DecodeDepth::Full);
60 assert_eq!(DecodeDepth::default(), DecodeDepth::Full);
61 }
62
63 #[test]
64 fn wire_names_match_display() {
65 for depth in [
66 DecodeDepth::Container,
67 DecodeDepth::Geometry,
68 DecodeDepth::Full,
69 ] {
70 assert_eq!(
71 serde_json::to_value(depth).expect("depth serializes"),
72 serde_json::Value::String(depth.to_string())
73 );
74 }
75 }
76}