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!(chrono::NaiveDate);
30has_no_extra_data!(());
31
32impl<T: HasExtraData> HasExtraData for Option<T> {
33    fn has_extra_data(&self) -> bool {
34        match self {
35            Some(inner) => inner.has_extra_data(),
36            None => false,
37        }
38    }
39}
40
41impl<K: Hash + Eq, V, S: BuildHasher> HasExtraData for HashMap<K, V, S> {
42    fn has_extra_data(&self) -> bool {
43        false
44    }
45}
46
47impl<Tz: TimeZone> HasExtraData for DateTime<Tz> {
48    fn has_extra_data(&self) -> bool {
49        false
50    }
51}