Skip to content

Commit b0f892e

Browse files
committed
major fixes
Signed-off-by: [email protected] <[email protected]>
1 parent 42f7e1a commit b0f892e

File tree

14 files changed

+114
-33
lines changed

14 files changed

+114
-33
lines changed

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ name = "cloudevents"
1919
serde = { version = "^1.0", features = ["derive"] }
2020
serde_json = "^1.0"
2121
serde-value = "^0.6"
22-
chrono = { version = "^0.4", features = ["serde"] }
22+
chrono = { version = "^0.4", default-features=false ,features = ["serde","alloc"] }
2323
delegate-attr = "^0.2"
2424
base64 = "^0.12"
2525
url = { version = "^2.1", features = ["serde"] }
26-
snafu = "^0.6"
26+
core-error = "0.0.1-rc4"
2727

28-
#[dependencies.snafu]
29-
#version = "^0.6"
30-
#default-features = false
31-
#features = ["guide"]
28+
[dependencies.snafu]
29+
version = "^0.6"
30+
default-features = false
3231

3332
[dependencies.no-std-compat]
34-
rand = { git = "https://gitlab.com/jD91mZM2/no-std-compat.git"}
33+
git = "https://gitlab.com/jD91mZM2/no-std-compat.git"
3534
features = ["alloc","compat_hash"]
3635

36+
3737
#no-std-compat = { version = "^0.4.1", features = ["alloc"] }
3838

3939
[target."cfg(not(target_arch = \"wasm32\"))".dependencies]

src/event/builder.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::Event;
1+
use super::{DisplayError, Event};
22
use snafu::Snafu;
33

44
/// Trait to implement a builder for [`Event`]:
@@ -41,7 +41,8 @@ pub enum Error {
4141
))]
4242
ParseTimeError {
4343
attribute_name: &'static str,
44-
source: chrono::ParseError,
44+
#[snafu(source(from(chrono::ParseError, DisplayError)))]
45+
source: DisplayError<chrono::ParseError>,
4546
},
4647
#[snafu(display(
4748
"Error while setting attribute '{}' with uri/uriref type: {}",
@@ -50,6 +51,7 @@ pub enum Error {
5051
))]
5152
ParseUrlError {
5253
attribute_name: &'static str,
53-
source: url::ParseError,
54+
#[snafu(source(from(url::ParseError, DisplayError)))]
55+
source: DisplayError<url::ParseError>,
5456
},
5557
}

src/event/displayerr.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use core::fmt::{self, Debug, Display};
2+
use snafu::Snafu;
3+
4+
#[derive(Clone)]
5+
pub struct DisplayError<T>(pub T);
6+
7+
impl<T> Debug for DisplayError<T>
8+
where
9+
T: Debug,
10+
{
11+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12+
self.0.fmt(f)
13+
}
14+
}
15+
16+
impl<T> Display for DisplayError<T>
17+
where
18+
T: Display,
19+
{
20+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21+
self.0.fmt(f)
22+
}
23+
}
24+
25+
impl<T> snafu::Error for DisplayError<T> where T: Display + Debug {}

src/event/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod attributes;
22
mod builder;
33
mod data;
4+
mod displayerr;
45
mod event;
56
mod extensions;
67
#[macro_use]
@@ -14,6 +15,7 @@ pub use attributes::{AttributeValue, AttributesReader, AttributesWriter};
1415
pub use builder::Error as EventBuilderError;
1516
pub use builder::EventBuilder;
1617
pub use data::Data;
18+
pub use displayerr::DisplayError;
1719
pub use event::Event;
1820
pub use extensions::ExtensionValue;
1921
pub(crate) use message::EventBinarySerializer;

src/event/spec_version.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::{v03, v10};
22
use serde::export::Formatter;
3+
use snafu::Snafu;
34
use std::convert::TryFrom;
45
use std::fmt;
56
use std::prelude::v1::*;
@@ -56,7 +57,7 @@ impl fmt::Display for UnknownSpecVersion {
5657
}
5758
}
5859

59-
impl std::error::Error for UnknownSpecVersion {}
60+
impl snafu::Error for UnknownSpecVersion {}
6061

6162
impl TryFrom<&str> for SpecVersion {
6263
type Error = UnknownSpecVersion;

src/event/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use chrono::{DateTime, Utc};
2+
use snafu;
23
use std::prelude::v1::*;
34
use url::Url;
45

src/event/v03/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl Default for Attributes {
162162
datacontenttype: None,
163163
schemaurl: None,
164164
subject: None,
165-
time: Some(Utc::now()),
165+
time: Some(chrono::offset::Utc::now()),
166166
}
167167
}
168168
}

src/event/v03/builder.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::Attributes as AttributesV03;
22
use crate::event::{
3-
Attributes, Data, Event, EventBuilderError, ExtensionValue, TryIntoTime, TryIntoUrl,
3+
Attributes, Data, DisplayError, Event, EventBuilderError, ExtensionValue, TryIntoTime,
4+
TryIntoUrl,
45
};
56
use crate::message::MessageAttributeValue;
67
use chrono::{DateTime, Utc};
@@ -36,7 +37,7 @@ impl EventBuilder {
3637
Err(e) => {
3738
self.error = Some(EventBuilderError::ParseUrlError {
3839
attribute_name: "source",
39-
source: e,
40+
source: DisplayError(e),
4041
})
4142
}
4243
};
@@ -59,7 +60,7 @@ impl EventBuilder {
5960
Err(e) => {
6061
self.error = Some(EventBuilderError::ParseTimeError {
6162
attribute_name: "time",
62-
source: e,
63+
source: DisplayError(e),
6364
})
6465
}
6566
};
@@ -99,7 +100,7 @@ impl EventBuilder {
99100
Err(e) => {
100101
self.error = Some(EventBuilderError::ParseUrlError {
101102
attribute_name: "schemaurl",
102-
source: e,
103+
source: DisplayError(e),
103104
})
104105
}
105106
};

src/event/v10/builder.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::Attributes as AttributesV10;
22
use crate::event::{
3-
Attributes, Data, Event, EventBuilderError, ExtensionValue, TryIntoTime, TryIntoUrl,
3+
Attributes, Data, DisplayError, Event, EventBuilderError, ExtensionValue, TryIntoTime,
4+
TryIntoUrl,
45
};
56
use crate::message::MessageAttributeValue;
67
use chrono::{DateTime, Utc};
@@ -36,7 +37,7 @@ impl EventBuilder {
3637
Err(e) => {
3738
self.error = Some(EventBuilderError::ParseUrlError {
3839
attribute_name: "source",
39-
source: e,
40+
source: DisplayError(e),
4041
})
4142
}
4243
};
@@ -59,7 +60,7 @@ impl EventBuilder {
5960
Err(e) => {
6061
self.error = Some(EventBuilderError::ParseTimeError {
6162
attribute_name: "time",
62-
source: e,
63+
source: DisplayError(e),
6364
})
6465
}
6566
};
@@ -99,7 +100,7 @@ impl EventBuilder {
99100
Err(e) => {
100101
self.error = Some(EventBuilderError::ParseUrlError {
101102
attribute_name: "dataschema",
102-
source: e,
103+
source: DisplayError(e),
103104
})
104105
}
105106
};

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
2626
#![no_std]
2727

28+
extern crate core_error;
2829
extern crate no_std_compat as std;
2930

3031
extern crate serde;

0 commit comments

Comments
 (0)