cloudevents/event/
types.rs1use chrono::{DateTime, Utc};
2use url::Url;
3
4pub trait TryIntoUrl {
6 fn into_url(self) -> Result<Url, url::ParseError>;
7}
8
9impl TryIntoUrl for Url {
10 fn into_url(self) -> Result<Url, url::ParseError> {
11 Ok(self)
12 }
13}
14
15impl TryIntoUrl for &str {
16 fn into_url(self) -> Result<Url, url::ParseError> {
17 Url::parse(self)
18 }
19}
20
21impl TryIntoUrl for String {
22 fn into_url(self) -> Result<Url, url::ParseError> {
23 self.as_str().into_url()
24 }
25}
26
27pub trait TryIntoTime {
29 fn into_time(self) -> Result<DateTime<Utc>, chrono::ParseError>;
30}
31
32impl TryIntoTime for DateTime<Utc> {
33 fn into_time(self) -> Result<DateTime<Utc>, chrono::ParseError> {
34 Ok(self)
35 }
36}
37
38impl TryIntoTime for &str {
39 fn into_time(self) -> Result<DateTime<Utc>, chrono::ParseError> {
40 Ok(DateTime::<Utc>::from(DateTime::parse_from_rfc3339(self)?))
41 }
42}
43
44impl TryIntoTime for String {
45 fn into_time(self) -> Result<DateTime<Utc>, chrono::ParseError> {
46 self.as_str().into_time()
47 }
48}
49
50pub type UriReference = String;