pub struct CloudEvent { /* private fields */ }Expand description
Implementations§
Source§impl CloudEvent
impl CloudEvent
Sourcepub fn new(
source: impl Into<String>,
id: impl Into<String>,
event_type: impl Into<String>,
) -> Result<Self, CloudEventError>
pub fn new( source: impl Into<String>, id: impl Into<String>, event_type: impl Into<String>, ) -> Result<Self, CloudEventError>
An event with the three attributes CloudEvents requires.
§Errors
CloudEventError::MissingAttribute if any of them is empty. The spec
says MUST be non-empty for all three, and an event missing one is one a
conformant receiver refuses — better refused where it is written.
Sourcepub fn with_data(self, data: Value) -> Self
pub fn with_data(self, data: Value) -> Self
The JSON data, which becomes an InboundEvent’s payload.
Sourcepub fn with_subject(self, subject: impl Into<String>) -> Self
pub fn with_subject(self, subject: impl Into<String>) -> Self
What this event is about within the producer — a run, an order, a
meter. Distinct from source, which names the producer itself.
Sourcepub fn with_extension(
self,
name: impl Into<String>,
value: Value,
) -> Result<Self, CloudEventError>
pub fn with_extension( self, name: impl Into<String>, value: Value, ) -> Result<Self, CloudEventError>
An extension attribute.
§Errors
CloudEventError::BadExtensionName unless the name is lowercase
letters and digits.
pub fn id(&self) -> &str
pub fn source(&self) -> &str
Sourcepub fn event_type(&self) -> &str
pub fn event_type(&self) -> &str
The type attribute. Spelled event_type because type is a keyword.
pub fn subject(&self) -> Option<&str>
Sourcepub const fn time(&self) -> Option<Timestamp>
pub const fn time(&self) -> Option<Timestamp>
The producer’s clock, if it set one. Never the runtime’s instant.
pub fn data(&self) -> Option<&Value>
Sourcepub fn extension(&self, name: &str) -> Option<&Value>
pub fn extension(&self, name: &str) -> Option<&Value>
One extension attribute, if the producer set it.
Sourcepub fn origin_id(&self) -> String
pub fn origin_id(&self) -> String
The pair CloudEvents defines uniqueness by, as one string.
origin_key is the construction and says why
it is shaped that way. The control-character refusal below is not what
makes this unforgeable — the encoding is — it is CloudEvents holding
its own attributes to what the specification allows.
Sourcepub fn into_inbound(self, transport_source: impl Into<String>) -> InboundEvent
pub fn into_inbound(self, transport_source: impl Into<String>) -> InboundEvent
This event as something a run can wait for.
source is not the event’s own: it is whoever the transport
authenticated. A self-asserted source would make the deduplication
identity a pair the sender controls both halves of, so one counterparty
could deduplicate against another’s messages by naming them. The
producer’s claim survives inside the id, as
origin_id — which keeps a relay carrying many
producers’ events from collapsing two of them into one.
Sourcepub fn from_json(body: &[u8]) -> Result<Self, CloudEventError>
pub fn from_json(body: &[u8]) -> Result<Self, CloudEventError>
Parse a structured-mode body.
§Errors
CloudEventError when the body is not a JSON object, names another
specversion, is missing a required attribute, or carries data this
plane does not accept.
Sourcepub fn from_http<'a, I>(
headers: I,
body: &[u8],
) -> Result<Self, CloudEventError>
pub fn from_http<'a, I>( headers: I, body: &[u8], ) -> Result<Self, CloudEventError>
Parse an HTTP message in whichever content mode it used.
Structured mode is chosen by the Content-Type; anything else is read
as binary mode, where the attributes are ce--prefixed headers and the
body is the data. headers is any iterator of (name, value); names
are compared case-insensitively, as HTTP requires.
§Errors
CloudEventError for the reasons from_json
gives, plus a percent-encoded header value that is not UTF-8.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
The structured-mode body, with sorted keys.
Through the canonical writer for the reason canon
gives: a body that is signed, or that a receiver verifies by
re-serializing what it parsed, needs bytes that are a function of the
event rather than of the order it was built in.
Trait Implementations§
Source§impl Clone for CloudEvent
impl Clone for CloudEvent
Source§impl Debug for CloudEvent
impl Debug for CloudEvent
Source§impl<'de> Deserialize<'de> for CloudEvent
impl<'de> Deserialize<'de> for CloudEvent
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for CloudEvent
impl PartialEq for CloudEvent
Source§impl Serialize for CloudEvent
impl Serialize for CloudEvent
impl StructuralPartialEq for CloudEvent
Auto Trait Implementations§
impl Freeze for CloudEvent
impl RefUnwindSafe for CloudEvent
impl Send for CloudEvent
impl Sync for CloudEvent
impl Unpin for CloudEvent
impl UnsafeUnpin for CloudEvent
impl UnwindSafe for CloudEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more