Skip to main content

CloudEvent

Struct CloudEvent 

Source
pub struct CloudEvent { /* private fields */ }
Expand description

One CloudEvents 1.0 message.

Constructed by new for emission and by from_json / from_http for ingestion; both paths run the same checks, so an event this plane emits is one it would accept.

Implementations§

Source§

impl CloudEvent

Source

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.

Source

pub fn with_data(self, data: Value) -> Self

The JSON data, which becomes an InboundEvent’s payload.

Source

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.

Source

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.

Source

pub fn id(&self) -> &str

Source

pub fn source(&self) -> &str

Source

pub fn event_type(&self) -> &str

The type attribute. Spelled event_type because type is a keyword.

Source

pub fn subject(&self) -> Option<&str>

Source

pub const fn time(&self) -> Option<Timestamp>

The producer’s clock, if it set one. Never the runtime’s instant.

Source

pub fn data(&self) -> Option<&Value>

Source

pub fn extension(&self, name: &str) -> Option<&Value>

One extension attribute, if the producer set it.

Source

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.

Source

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.

Source

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.

Source

pub fn from_http<'a, I>( headers: I, body: &[u8], ) -> Result<Self, CloudEventError>
where I: IntoIterator<Item = (&'a str, &'a str)>,

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.

Source

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.

Source

pub fn to_value(&self) -> Value

The structured-mode JSON, attributes flat beside data.

Trait Implementations§

Source§

impl Clone for CloudEvent

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CloudEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for CloudEvent

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for CloudEvent

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for CloudEvent

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for CloudEvent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more