use crate::{AssetId, de_opt_asset_ref};
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(default)]
#[derive(Default)]
pub struct FpsCounter {
#[serde(deserialize_with = "de_opt_asset_ref")]
pub label: Option<AssetId>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn an_unset_label_suppresses_the_on_screen_readout() {
assert!(FpsCounter::default().label.is_none());
assert!(
serde_json::from_str::<FpsCounter>(r#"{"label":""}"#)
.unwrap()
.label
.is_none()
);
}
#[test]
fn a_named_label_parses_and_round_trips_through_postcard() {
crate::test_support::install_resolvers();
let c: FpsCounter = serde_json::from_str(r#"{"label":"fps_chip"}"#).unwrap();
assert_eq!(c.label, Some(AssetId(8)));
let bytes = postcard::to_allocvec(&c).unwrap();
let back: FpsCounter = postcard::from_bytes(&bytes).unwrap();
assert_eq!(back.label, Some(AssetId(8)));
}
}