component_events/
descriptor.rs1use crate::events::ExitStatus;
6use fidl_fuchsia_component as fcomponent;
7
8#[derive(Clone, Eq, PartialEq, PartialOrd, Ord, Debug)]
9pub struct EventDescriptor {
10 pub event_type: Option<fcomponent::EventType>,
11 pub capability_name: Option<String>,
12 pub target_moniker: Option<String>,
13 pub exit_status: Option<ExitStatus>,
14 pub event_is_ok: Option<bool>,
15}
16
17impl TryFrom<&fcomponent::Event> for EventDescriptor {
18 type Error = anyhow::Error;
19
20 fn try_from(event: &fcomponent::Event) -> Result<Self, Self::Error> {
21 let event_type = event.header.as_ref().and_then(|header| header.event_type.clone());
23 let target_moniker = event.header.as_ref().and_then(|header| header.moniker.clone());
24 let capability_name = match &event.payload {
25 Some(fcomponent::EventPayload::CapabilityRequested(
26 fcomponent::CapabilityRequestedPayload { name, .. },
27 )) => name.clone(),
28 _ => None,
29 };
30 let exit_status = match &event.payload {
31 Some(fcomponent::EventPayload::Stopped(fcomponent::StoppedPayload {
32 status, ..
33 })) => status.map(|val| val.into()),
34 _ => None,
35 };
36 let event_is_ok = match &event.payload {
37 Some(_) => Some(true),
38 _ => None,
39 };
40
41 Ok(EventDescriptor {
42 event_type,
43 target_moniker,
44 capability_name,
45 exit_status,
46 event_is_ok,
47 })
48 }
49}