|
1 | 1 | use crate::event::ExtensionValue; |
2 | 2 | use chrono::{DateTime, Utc}; |
| 3 | +use serde::export::Formatter; |
3 | 4 | use std::convert::TryInto; |
| 5 | +use std::fmt; |
4 | 6 | use url::Url; |
5 | 7 |
|
6 | 8 | /// Union type representing a [CloudEvent context attribute type](https://github.com/cloudevents/spec/blob/v1.0/spec.md#type-system) |
| 9 | +#[derive(PartialEq, Eq, Debug, Clone)] |
7 | 10 | pub enum MessageAttributeValue { |
8 | 11 | Boolean(bool), |
9 | 12 | Integer(i64), |
@@ -39,16 +42,16 @@ impl TryInto<Url> for MessageAttributeValue { |
39 | 42 | } |
40 | 43 | } |
41 | 44 |
|
42 | | -impl ToString for MessageAttributeValue { |
43 | | - fn to_string(&self) -> String { |
| 45 | +impl fmt::Display for MessageAttributeValue { |
| 46 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
44 | 47 | match self { |
45 | | - MessageAttributeValue::Boolean(b) => b.to_string(), |
46 | | - MessageAttributeValue::Integer(i) => i.to_string(), |
47 | | - MessageAttributeValue::String(s) => s.clone(), |
48 | | - MessageAttributeValue::Binary(v) => base64::encode(v), |
49 | | - MessageAttributeValue::Uri(u) => u.to_string(), |
50 | | - MessageAttributeValue::UriRef(u) => u.to_string(), |
51 | | - MessageAttributeValue::DateTime(d) => d.to_rfc3339(), |
| 48 | + MessageAttributeValue::Boolean(b) => write!(f, "{}", b), |
| 49 | + MessageAttributeValue::Integer(i) => write!(f, "{}", i), |
| 50 | + MessageAttributeValue::String(s) => write!(f, "{}", s), |
| 51 | + MessageAttributeValue::Binary(v) => write!(f, "{}", base64::encode(v)), |
| 52 | + MessageAttributeValue::Uri(u) => write!(f, "{}", u.to_string()), |
| 53 | + MessageAttributeValue::UriRef(u) => write!(f, "{}", u.to_string()), |
| 54 | + MessageAttributeValue::DateTime(d) => write!(f, "{}", d.to_rfc3339()), |
52 | 55 | } |
53 | 56 | } |
54 | 57 | } |
|
0 commit comments