Skip to content

Commit

Permalink
Add iter() in cloudevents::event::Attributes (#89)
Browse files Browse the repository at this point in the history
* Add iter in Attributes

Signed-off-by: Francesco Guardiani <[email protected]>

* Removed bad import

Signed-off-by: Francesco Guardiani <[email protected]>
  • Loading branch information
slinkydeveloper authored Oct 19, 2020
1 parent fbadb33 commit 1858a1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/event/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ impl Attributes {
_ => self,
}
}

pub fn iter(&self) -> impl Iterator<Item = (&str, AttributeValue)> {
match self {
Attributes::V03(a) => AttributesIter::IterV03(a.into_iter()),
Attributes::V10(a) => AttributesIter::IterV10(a.into_iter()),
}
}
}

#[cfg(not(target_arch = "wasm32"))]
Expand Down
9 changes: 3 additions & 6 deletions src/event/event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
AttributeValue, Attributes, AttributesIter, AttributesReader, AttributesV10, AttributesWriter,
Data, ExtensionValue, SpecVersion,
AttributeValue, Attributes, AttributesReader, AttributesV10, AttributesWriter, Data,
ExtensionValue, SpecVersion,
};
use crate::event::attributes::DataAttributesWriter;
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -82,10 +82,7 @@ impl Event {
/// Returns an [`Iterator`] for all the available [CloudEvents Context attributes](https://github.com/cloudevents/spec/blob/master/spec.md#context-attributes), excluding extensions.
/// This iterator does not contain the `data` field.
pub fn iter_attributes(&self) -> impl Iterator<Item = (&str, AttributeValue)> {
match &self.attributes {
Attributes::V03(a) => AttributesIter::IterV03(a.into_iter()),
Attributes::V10(a) => AttributesIter::IterV10(a.into_iter()),
}
self.attributes.iter()
}

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

0 comments on commit 1858a1c

Please sign in to comment.