1use crate::geom::{DisplayId, LogicalRect};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13pub struct Anchor {
14 pub screen_rect: LogicalRect,
16 pub display_id: DisplayId,
18 #[serde(default)]
20 pub content_hash: Option<String>,
21}
22
23impl Anchor {
24 pub const fn new(screen_rect: LogicalRect, display_id: DisplayId) -> Self {
26 Self {
27 screen_rect,
28 display_id,
29 content_hash: None,
30 }
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37
38 #[test]
39 fn reserved_field_stays_on_the_wire() {
40 let anchor = Anchor::new(LogicalRect::new(100.0, 200.0, 340.0, 90.0), DisplayId(1));
41 let json = serde_json::to_value(&anchor).unwrap();
42 assert!(
43 json.get("content_hash")
44 .is_some_and(serde_json::Value::is_null),
45 "content_hash must serialize as null, not vanish"
46 );
47 }
48
49 #[test]
50 fn absent_reserved_field_deserializes() {
51 let json = r#"{"screen_rect":[100,200,340,90],"display_id":1}"#;
52 let anchor: Anchor = serde_json::from_str(json).unwrap();
53 assert_eq!(anchor.content_hash, None);
54 }
55}