relay_event_schema/protocol/contexts/
unity.rs1use relay_protocol::{Annotated, Empty, FromValue, IntoValue, Object, Value};
2
3use crate::processor::ProcessValue;
4
5#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
9pub struct UnityContext {
10 pub copy_texture_support: Annotated<String>,
12
13 pub editor_version: Annotated<String>,
15
16 pub install_mode: Annotated<String>,
18
19 pub rendering_threading_mode: Annotated<String>,
21
22 pub target_frame_rate: Annotated<String>,
24
25 #[metastructure(additional_properties, retain = true, pii = "maybe")]
27 pub other: Object<Value>,
28}
29
30impl super::DefaultContext for UnityContext {
31 fn default_key() -> &'static str {
32 "unity"
33 }
34
35 fn from_context(context: super::Context) -> Option<Self> {
36 match context {
37 super::Context::Unity(c) => Some(*c),
38 _ => None,
39 }
40 }
41
42 fn cast(context: &super::Context) -> Option<&Self> {
43 match context {
44 super::Context::Unity(c) => Some(c),
45 _ => None,
46 }
47 }
48
49 fn cast_mut(context: &mut super::Context) -> Option<&mut Self> {
50 match context {
51 super::Context::Unity(c) => Some(c),
52 _ => None,
53 }
54 }
55
56 fn into_context(self) -> super::Context {
57 super::Context::Unity(Box::new(self))
58 }
59}
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64 use crate::protocol::Context;
65 use crate::protocol::contexts::DefaultContext;
66
67 #[test]
68 fn test_unity_context_roundtrip() {
69 let json = r#"{
70 "copy_texture_support": "Basic, Copy3D, DifferentTypes, TextureToRT, RTToTexture",
71 "editor_version": "2022.1.23f1",
72 "install_mode": "Store",
73 "rendering_threading_mode": "LegacyJobified",
74 "target_frame_rate": "-1",
75 "other": "value",
76 "type": "unity"
77}"#;
78 let context = Annotated::new(Context::Unity(Box::new(UnityContext {
79 copy_texture_support: Annotated::new(
80 "Basic, Copy3D, DifferentTypes, TextureToRT, RTToTexture".to_owned(),
81 ),
82 editor_version: Annotated::new("2022.1.23f1".to_owned()),
83 install_mode: Annotated::new("Store".to_owned()),
84 rendering_threading_mode: Annotated::new("LegacyJobified".to_owned()),
85 target_frame_rate: Annotated::new("-1".to_owned()),
86 other: {
87 let mut map = Object::new();
88 map.insert(
89 "other".to_owned(),
90 Annotated::new(Value::String("value".to_owned())),
91 );
92 map
93 },
94 })));
95
96 assert_eq!(context, Annotated::from_json(json).unwrap());
97 assert_eq!(json, context.to_json_pretty().unwrap());
98 }
99
100 #[test]
101 fn test_unity_context_default_key() {
102 assert_eq!(UnityContext::default_key(), "unity");
103 }
104
105 #[test]
106 fn test_unity_context_minimal() {
107 let json = r#"{
108 "type": "unity"
109}"#;
110 let context = Annotated::new(Context::Unity(Box::default()));
111 assert_eq!(context, Annotated::from_json(json).unwrap());
112 assert_eq!(json, context.to_json_pretty().unwrap());
113 }
114}