[−][src]Struct cloudevents::Event
Data structure that represents a CloudEvent.
It provides methods to get the attributes through AttributesReader
and write them through AttributesWriter
.
It also provides methods to read and write the event data
use cloudevents::Event; use cloudevents::event::AttributesReader; // Create an event using the Default trait let mut e = Event::default(); e.write_data( "application/json", None, serde_json::json!({"hello": "world"}) ); // Print the event id println!("Event id: {}", e.get_id()); // Get the event data let data: serde_json::Value = e.try_get_data().unwrap().unwrap(); println!("Event data: {}", data)
Fields
attributes: Attributes
data: Option<Data>
Methods
impl Event
[src]
pub fn remove_data(&mut self)
[src]
pub fn write_data<S: Into<String>, D: Into<Data>>(
&mut self,
content_type: S,
schema: Option<S>,
value: D
)
[src]
&mut self,
content_type: S,
schema: Option<S>,
value: D
)
Write data into the Event
. You must provide a content_type
and you can optionally provide a schema
.
use cloudevents::Event; use serde_json::json; use std::convert::Into; let mut e = Event::default(); e.write_data("application/json", None, json!({}))
pub fn get_data<T: Sized + From<Data>>(&self) -> Option<T>
[src]
pub fn try_get_data<T: Sized + TryFrom<Data, Error = E>, E: Error>(
&self
) -> Option<Result<T, E>>
[src]
&self
) -> Option<Result<T, E>>
pub fn into_data<T: Sized + TryFrom<Data, Error = E>, E: Error>(
self
) -> Option<Result<T, E>>
[src]
self
) -> Option<Result<T, E>>
Trait Implementations
impl AttributesReader for Event
[src]
fn get_id(&self) -> &str
[src]
fn get_source(&self) -> &str
[src]
fn get_specversion(&self) -> SpecVersion
[src]
fn get_type(&self) -> &str
[src]
fn get_datacontenttype(&self) -> Option<&str>
[src]
fn get_dataschema(&self) -> Option<&str>
[src]
fn get_subject(&self) -> Option<&str>
[src]
fn get_time(&self) -> Option<&DateTime<FixedOffset>>
[src]
fn get_extension(&self, extension_name: &str) -> Option<&ExtensionValue>
[src]
fn get_extensions(&self) -> Vec<(&str, &ExtensionValue)>
[src]
impl AttributesWriter for Event
[src]
fn set_id(&mut self, id: impl Into<String>)
[src]
fn set_source(&mut self, source: impl Into<String>)
[src]
fn set_type(&mut self, ty: impl Into<String>)
[src]
fn set_subject(&mut self, subject: Option<impl Into<String>>)
[src]
fn set_time(&mut self, time: Option<impl Into<DateTime<FixedOffset>>>)
[src]
fn set_extension<'name, 'event: 'name>(
&'event mut self,
extension_name: &'name str,
extension_value: impl Into<ExtensionValue>
)
[src]
&'event mut self,
extension_name: &'name str,
extension_value: impl Into<ExtensionValue>
)
fn remove_extension<'name, 'event: 'name>(
&'event mut self,
extension_name: &'name str
) -> Option<ExtensionValue>
[src]
&'event mut self,
extension_name: &'name str
) -> Option<ExtensionValue>
impl Default for Event
[src]
Auto Trait Implementations
impl RefUnwindSafe for Event
impl Send for Event
impl Sync for Event
impl Unpin for Event
impl UnwindSafe for Event
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,