Struct cap_sdk::TypedEvent
source · [−]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: u64The timestamp in ms.
caller: PrincipalThe caller that initiated the call on the token contract.
details: TDetails of the transaction.
Implementations
sourceimpl<T: IntoEvent + TryFromEvent + Clone> TypedEvent<T>
impl<T: IntoEvent + TryFromEvent + Clone> TypedEvent<T>
Trait Implementations
sourceimpl<T: Clone> Clone for TypedEvent<T> where
T: TryFromEvent + IntoEvent + Sized + Clone,
impl<T: Clone> Clone for TypedEvent<T> where
T: TryFromEvent + IntoEvent + Sized + Clone,
sourcefn clone(&self) -> TypedEvent<T>
fn clone(&self) -> TypedEvent<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl<T: TryFromEvent + IntoEvent + Clone> Into<Event> for TypedEvent<T>
impl<T: TryFromEvent + IntoEvent + Clone> Into<Event> for TypedEvent<T>
sourceimpl<T: TryFromEvent + IntoEvent + Clone> TryFrom<Event> for TypedEvent<T>
impl<T: TryFromEvent + IntoEvent + Clone> TryFrom<Event> for TypedEvent<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for TypedEvent<T> where
T: RefUnwindSafe,
impl<T> Send for TypedEvent<T> where
T: Send,
impl<T> Sync for TypedEvent<T> where
T: Sync,
impl<T> Unpin for TypedEvent<T> where
T: Unpin,
impl<T> UnwindSafe for TypedEvent<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more