Skip to content

Commit 1858a1c

Browse files
Add iter() in cloudevents::event::Attributes (cloudevents#89)
* Add iter in Attributes Signed-off-by: Francesco Guardiani <[email protected]> * Removed bad import Signed-off-by: Francesco Guardiani <[email protected]>
1 parent fbadb33 commit 1858a1c

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/event/attributes.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,13 @@ impl Attributes {
243243
_ => self,
244244
}
245245
}
246+
247+
pub fn iter(&self) -> impl Iterator<Item = (&str, AttributeValue)> {
248+
match self {
249+
Attributes::V03(a) => AttributesIter::IterV03(a.into_iter()),
250+
Attributes::V10(a) => AttributesIter::IterV10(a.into_iter()),
251+
}
252+
}
246253
}
247254

248255
#[cfg(not(target_arch = "wasm32"))]

src/event/event.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{
2-
AttributeValue, Attributes, AttributesIter, AttributesReader, AttributesV10, AttributesWriter,
3-
Data, ExtensionValue, SpecVersion,
2+
AttributeValue, Attributes, AttributesReader, AttributesV10, AttributesWriter, Data,
3+
ExtensionValue, SpecVersion,
44
};
55
use crate::event::attributes::DataAttributesWriter;
66
use chrono::{DateTime, Utc};
@@ -82,10 +82,7 @@ impl Event {
8282
/// Returns an [`Iterator`] for all the available [CloudEvents Context attributes](https://github.com/cloudevents/spec/blob/master/spec.md#context-attributes), excluding extensions.
8383
/// This iterator does not contain the `data` field.
8484
pub fn iter_attributes(&self) -> impl Iterator<Item = (&str, AttributeValue)> {
85-
match &self.attributes {
86-
Attributes::V03(a) => AttributesIter::IterV03(a.into_iter()),
87-
Attributes::V10(a) => AttributesIter::IterV10(a.into_iter()),
88-
}
85+
self.attributes.iter()
8986
}
9087

9188
/// Get all the [extensions](https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes)

0 commit comments

Comments
 (0)