launchdarkly_server_sdk_evaluation/contexts/
context_serde_helpers.rs

1use crate::contexts::context_serde::Meta;
2use serde::Deserialize;
3
4/// If a bool is false, there is no need to serialize it in
5/// a context JSON representation.
6pub(super) fn is_false_bool_option(b: &Option<bool>) -> bool {
7    match b {
8        None => true,
9        Some(b) => !b,
10    }
11}
12
13/// If a vector is empty, there is no need to serialize it in
14/// a context JSON representation.
15pub(super) fn is_empty_vec_option<'re, T>(v: &Option<Vec<T>>) -> bool
16where
17    T: Deserialize<'re>,
18{
19    match v {
20        None => true,
21        Some(v) => v.is_empty(),
22    }
23}
24
25/// If the _meta block's members are none, then there is no
26/// need to serialize it in the context JSON representation.
27pub(super) fn is_none_meta_option(m: &Option<Meta>) -> bool {
28    match m {
29        None => true,
30        Some(m) => m.secondary.is_none() && is_empty_vec_option(&m.private_attributes),
31    }
32}