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
37
38
39
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, JsonSchema)]
pub struct Attribute {
pub key: String,
pub value: String,
}
pub fn attr<K: ToString, V: ToString>(key: K, value: V) -> Attribute {
Attribute {
key: key.to_string(),
value: value.to_string(),
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::addresses::HumanAddr;
use crate::Uint128;
#[test]
fn attr_works_for_different_types() {
let expeceted = Attribute {
key: "foo".to_string(),
value: "42".to_string(),
};
assert_eq!(attr("foo", "42"), expeceted);
assert_eq!(attr("foo".to_string(), "42"), expeceted);
assert_eq!(attr("foo", "42".to_string()), expeceted);
assert_eq!(attr("foo", HumanAddr::from("42")), expeceted);
assert_eq!(attr("foo", Uint128(42)), expeceted);
assert_eq!(attr("foo", 42), expeceted);
}
}