1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use crate::{Entity, ID};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
pub struct Metadata {
#[serde(flatten)]
pub inner: HashMap<String, String>,
}
impl Metadata {
pub fn new() -> Self {
Self {
inner: HashMap::new(),
}
}
pub fn new_kv(key: String, value: String) -> Self {
let mut inner = HashMap::new();
inner.insert(key, value);
Self::from(inner)
}
}
impl From<HashMap<String, String>> for Metadata {
fn from(inner: HashMap<String, String>) -> Self {
Self { inner }
}
}
pub trait Meta<T: PartialEq>: Entity<T> {
fn metadata(&self) -> &Metadata;
fn account_id(&self) -> &ID;
}