monzo_webhook/
has_extra_data.rs

1use std::{
2    collections::HashMap,
3    hash::{BuildHasher, Hash},
4};
5
6use chrono::{DateTime, TimeZone};
7
8macro_rules! has_no_extra_data {
9    ($type: ty) => {
10        impl HasExtraData for $type {
11            fn has_extra_data(&self) -> bool {
12                false
13            }
14        }
15    };
16}
17
18pub trait HasExtraData {
19    /// Recursively check if any extra data is present on this object or
20    /// any of it's children.
21    fn has_extra_data(&self) -> bool;
22}
23
24has_no_extra_data!(String);
25has_no_extra_data!(bool);
26has_no_extra_data!(f64);
27has_no_extra_data!(u64);
28has_no_extra_data!(i64);
29has_no_extra_data!(());
30
31impl<T: HasExtraData> HasExtraData for Option<T> {
32    fn has_extra_data(&self) -> bool {
33        match self {
34            Some(inner) => inner.has_extra_data(),
35            None => false,
36        }
37    }
38}
39
40impl<K: Hash + Eq, V, S: BuildHasher> HasExtraData for HashMap<K, V, S> {
41    fn has_extra_data(&self) -> bool {
42        false
43    }
44}
45
46impl<Tz: TimeZone> HasExtraData for DateTime<Tz> {
47    fn has_extra_data(&self) -> bool {
48        false
49    }
50}