use std::fmt;
#[cfg(feature = "schema")]
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize,
)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
#[serde(rename_all = "snake_case")]
pub enum DecodeDepth {
Container,
Geometry,
#[default]
Full,
}
impl DecodeDepth {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Container => "container",
Self::Geometry => "geometry",
Self::Full => "full",
}
}
}
impl fmt::Display for DecodeDepth {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad(self.as_str())
}
}
#[cfg(test)]
mod tests {
use super::DecodeDepth;
#[test]
fn depths_order_by_what_they_transfer() {
assert!(DecodeDepth::Container < DecodeDepth::Geometry);
assert!(DecodeDepth::Geometry < DecodeDepth::Full);
assert_eq!(DecodeDepth::default(), DecodeDepth::Full);
}
#[test]
fn wire_names_match_display() {
for depth in [
DecodeDepth::Container,
DecodeDepth::Geometry,
DecodeDepth::Full,
] {
assert_eq!(
serde_json::to_value(depth).expect("depth serializes"),
serde_json::Value::String(depth.to_string())
);
}
}
}