pub struct TypedEvent<T> where
    T: TryFromEvent + IntoEvent + Sized + Clone, 
{ pub time: u64, pub caller: Principal, pub details: T, }
Expand description

A Cap event with typed details.

This type implements TryFrom<Event>. This allows easy conversion from an Event into this type, provided the Event’s details are the correct type. Internally this uses [TryFromDetails], which is why this type is bounded on TryFromDetails + IntoDetails + Sized.

Any structures that take Event use impl Into<Event>, so this structure can be used interchangably with Event.

Examples

Creating a TypedEvent from an Event

pub struct TransactionDetails {
    foo: String,
    bar: u64,
}

// This is an example of the type of event that would be retrieved from
// a call to Cap. It has the required details to be cast into a typed
// event with our transaction details type.
let event = Event {
    time: 0,
    caller: Principal::anonymous(),
    status: EventStatus::Completed,
    operation: String::from("transfer"),
    details: vec![
        ("foo".to_owned(), DetailValue::Text("foo".to_owned())),
        ("bar".to_owned(), DetailValue::U64(64))
    ],
};

if let Ok(_typed_event) = TypedEvent::<TransactionDetails>::try_from(event) {
    // ...
} else {
    panic!("Failed to cast event to typed event.")
}

Fields

time: u64

The timestamp in ms.

caller: Principal

The caller that initiated the call on the token contract.

details: T

Details of the transaction.

Implementations

The operation of the event

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Converts this type into the (usually inferred) input type.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.