---
source: dial9-trace-format-derive/src/lib.rs
expression: "expand_to_string(quote!\n{\n    struct PollStart\n    {\n        #[traceevent(timestamp)] timestamp_ns: u64, worker_id: u64, task_id:\n        u64,\n    }\n})"
---
#[derive(Debug, Clone)]
struct PollStartRef<'a> {
    pub timestamp_ns: u64,
    pub worker_id: <u64 as ::dial9_trace_format::TraceField>::Ref<'a>,
    pub task_id: <u64 as ::dial9_trace_format::TraceField>::Ref<'a>,
}
impl ::dial9_trace_format::TraceEvent for PollStart {
    type Ref<'a> = PollStartRef<'a>;
    fn event_name() -> &'static str {
        "PollStart"
    }
    fn field_defs() -> Vec<::dial9_trace_format::schema::FieldDef> {
        vec![
            ::dial9_trace_format::schema::FieldDef::new("worker_id", < u64 as
            ::dial9_trace_format::TraceField > ::field_type(),),
            ::dial9_trace_format::schema::FieldDef::new("task_id", < u64 as
            ::dial9_trace_format::TraceField > ::field_type(),)
        ]
    }
    fn timestamp(&self) -> u64 {
        self.timestamp_ns
    }
    fn encode_fields<W: ::std::io::Write>(
        &self,
        enc: &mut ::dial9_trace_format::EventEncoder<'_, W>,
    ) -> ::std::io::Result<()> {
        <u64 as ::dial9_trace_format::TraceField>::encode(&self.worker_id, enc)?;
        <u64 as ::dial9_trace_format::TraceField>::encode(&self.task_id, enc)?;
        Ok(())
    }
    fn decode<'a>(
        timestamp_ns: Option<u64>,
        fields: &[::dial9_trace_format::types::FieldValueRef<'a>],
        field_defs: &[::dial9_trace_format::schema::FieldDef],
    ) -> Option<Self::Ref<'a>> {
        Some(PollStartRef {
            timestamp_ns: timestamp_ns?,
            worker_id: {
                let val = field_defs
                    .iter()
                    .zip(fields.iter())
                    .find(|(f, _)| f.name() == "worker_id")
                    .map(|(_, v)| v);
                match val {
                    Some(v) => <u64 as ::dial9_trace_format::TraceField>::decode_ref(v)?,
                    None => <u64 as ::dial9_trace_format::TraceField>::decode_missing()?,
                }
            },
            task_id: {
                let val = field_defs
                    .iter()
                    .zip(fields.iter())
                    .find(|(f, _)| f.name() == "task_id")
                    .map(|(_, v)| v);
                match val {
                    Some(v) => <u64 as ::dial9_trace_format::TraceField>::decode_ref(v)?,
                    None => <u64 as ::dial9_trace_format::TraceField>::decode_missing()?,
                }
            },
        })
    }
}
