relay_event_schema/protocol/contexts/
performance_score.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)]
10
11pub struct PerformanceScoreContext {
12 pub score_profile_version: Annotated<String>,
14 #[metastructure(additional_properties, retain = true)]
16 pub other: Object<Value>,
17}
18
19impl super::DefaultContext for PerformanceScoreContext {
20 fn default_key() -> &'static str {
21 "performance_score"
22 }
23
24 fn from_context(context: super::Context) -> Option<Self> {
25 match context {
26 super::Context::PerformanceScore(c) => Some(*c),
27 _ => None,
28 }
29 }
30
31 fn cast(context: &super::Context) -> Option<&Self> {
32 match context {
33 super::Context::PerformanceScore(c) => Some(c),
34 _ => None,
35 }
36 }
37
38 fn cast_mut(context: &mut super::Context) -> Option<&mut Self> {
39 match context {
40 super::Context::PerformanceScore(c) => Some(c),
41 _ => None,
42 }
43 }
44
45 fn into_context(self) -> super::Context {
46 super::Context::PerformanceScore(Box::new(self))
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53 use crate::protocol::Context;
54
55 #[test]
56 fn test_performance_score_context() {
57 let json = r#"{
58 "score_profile_version": "alpha",
59 "type": "performancescore"
60}"#;
61 let context = Annotated::new(Context::PerformanceScore(Box::new(
62 PerformanceScoreContext {
63 score_profile_version: Annotated::new("alpha".to_string()),
64 other: Object::default(),
65 },
66 )));
67
68 assert_eq!(context, Annotated::from_json(json).unwrap());
69 assert_eq!(json, context.to_json_pretty().unwrap());
70 }
71}