Skip to content

Commit 7084937

Browse files
committed
Attributes Iterator finalise cloudevents#3
Signed-off-by: Pranav Bhatt <adpranavb2000@gmail.com>
1 parent 69d8335 commit 7084937

File tree

8 files changed

+25
-21
lines changed

8 files changed

+25
-21
lines changed

src/event/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub(crate) trait DataAttributesWriter {
7171
}
7272

7373
#[derive(PartialEq, Debug, Clone, Copy)]
74-
pub enum AttributesIter<'a> {
74+
pub(crate) enum AttributesIter<'a> {
7575
IterV03(AttributesIntoIteratorV03<'a>),
7676
IterV10(AttributesIntoIteratorV10<'a>),
7777
}

src/event/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl Default for Event {
7979

8080
impl Event {
8181
/// Returns an `Iterator` for `Attributes`
82-
pub fn attributes_iter(&self) -> impl Iterator<Item = (&str, AttributeValue<'_>)> {
82+
pub fn attributes_iter<'a>(&'a self) -> impl Iterator<Item = (&'a str, AttributeValue<'a>)> {
8383
match &self.attributes {
8484
Attributes::V03(a) => AttributesIter::IterV03(a.into_iter()),
8585
Attributes::V10(a) => AttributesIter::IterV10(a.into_iter()),

src/event/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ mod spec_version;
1010
mod types;
1111

1212
pub use attributes::Attributes;
13-
pub use attributes::{AttributeValue, AttributesIter, AttributesReader, AttributesWriter};
13+
pub(crate) use attributes::AttributesIter;
14+
pub use attributes::{AttributeValue, AttributesReader, AttributesWriter};
1415
pub use builder::Error as EventBuilderError;
1516
pub use builder::EventBuilder;
1617
pub use data::Data;

src/event/v03/attributes.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,26 @@ impl<'a> Iterator for AttributesIntoIterator<'a> {
5252
type Item = (&'a str, AttributeValue<'a>);
5353
fn next(&mut self) -> Option<Self::Item> {
5454
let result = match self.index {
55-
0 => Some(("id", AttributeValue::String(&self.attributes.id))),
56-
1 => Some(("type", AttributeValue::String(&self.attributes.ty))),
57-
2 => Some(("source", AttributeValue::URIRef(&self.attributes.source))),
58-
3 => self
55+
0 => Some(("specversion", AttributeValue::SpecVersion(SpecVersion::V03))),
56+
1 => Some(("id", AttributeValue::String(&self.attributes.id))),
57+
2 => Some(("type", AttributeValue::String(&self.attributes.ty))),
58+
3 => Some(("source", AttributeValue::URIRef(&self.attributes.source))),
59+
4 => self
5960
.attributes
6061
.datacontenttype
6162
.as_ref()
6263
.map(|v| ("datacontenttype", AttributeValue::String(v))),
63-
4 => self
64+
5 => self
6465
.attributes
6566
.schemaurl
6667
.as_ref()
6768
.map(|v| ("schemaurl", AttributeValue::URIRef(v))),
68-
5 => self
69+
6 => self
6970
.attributes
7071
.subject
7172
.as_ref()
7273
.map(|v| ("subject", AttributeValue::String(v))),
73-
6 => self
74+
7 => self
7475
.attributes
7576
.time
7677
.as_ref()

src/event/v03/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod format;
44
mod message;
55

66
pub use attributes::Attributes;
7-
pub use attributes::AttributesIntoIterator;
7+
pub(crate) use attributes::AttributesIntoIterator;
88
pub(crate) use attributes::ATTRIBUTE_NAMES;
99
pub use builder::EventBuilder;
1010
pub(crate) use format::EventFormatDeserializer;

src/event/v10/attributes.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,26 @@ impl<'a> Iterator for AttributesIntoIterator<'a> {
5252
type Item = (&'a str, AttributeValue<'a>);
5353
fn next(&mut self) -> Option<Self::Item> {
5454
let result = match self.index {
55-
0 => Some(("id", AttributeValue::String(&self.attributes.id))),
56-
1 => Some(("type", AttributeValue::String(&self.attributes.ty))),
57-
2 => Some(("source", AttributeValue::URIRef(&self.attributes.source))),
58-
3 => self
55+
0 => Some(("specversion", AttributeValue::SpecVersion(SpecVersion::V10))),
56+
1 => Some(("id", AttributeValue::String(&self.attributes.id))),
57+
2 => Some(("type", AttributeValue::String(&self.attributes.ty))),
58+
3 => Some(("source", AttributeValue::URIRef(&self.attributes.source))),
59+
4 => self
5960
.attributes
6061
.datacontenttype
6162
.as_ref()
6263
.map(|v| ("datacontenttype", AttributeValue::String(v))),
63-
4 => self
64+
5 => self
6465
.attributes
6566
.dataschema
6667
.as_ref()
6768
.map(|v| ("dataschema", AttributeValue::URI(v))),
68-
5 => self
69+
6 => self
6970
.attributes
7071
.subject
7172
.as_ref()
7273
.map(|v| ("subject", AttributeValue::String(v))),
73-
6 => self
74+
7 => self
7475
.attributes
7576
.time
7677
.as_ref()

src/event/v10/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod format;
44
mod message;
55

66
pub use attributes::Attributes;
7-
pub use attributes::AttributesIntoIterator;
7+
pub(crate) use attributes::AttributesIntoIterator;
88
pub(crate) use attributes::ATTRIBUTE_NAMES;
99
pub use builder::EventBuilder;
1010
pub(crate) use format::EventFormatDeserializer;

tests/attributes_iter.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod test_data;
22
use cloudevents::event::AttributeValue;
3+
use cloudevents::event::SpecVersion;
34
use test_data::*;
45

56
#[test]
@@ -8,7 +9,7 @@ fn iter_v10_test() {
89
let mut iter_v10 = in_event.attributes_iter();
910

1011
assert_eq!(
11-
("id", AttributeValue::String("0001")),
12+
("specversion", AttributeValue::SpecVersion(SpecVersion::V10)),
1213
iter_v10.next().unwrap()
1314
);
1415
}
@@ -19,7 +20,7 @@ fn iter_v03_test() {
1920
let mut iter_v03 = in_event.attributes_iter();
2021

2122
assert_eq!(
22-
("id", AttributeValue::String("0001")),
23+
("specversion", AttributeValue::SpecVersion(SpecVersion::V03)),
2324
iter_v03.next().unwrap()
2425
);
2526
}

0 commit comments

Comments
 (0)