remotia_profilation_utils/time/
diff.rs1use async_trait::async_trait;
2
3use remotia_core::{
4 common::helpers::time::now_timestamp,
5 traits::{FrameProcessor, FrameProperties},
6};
7
8pub struct TimestampDiffCalculator<K> {
9 source_id: K,
10 diff_id: K,
11}
12
13impl<K> TimestampDiffCalculator<K> {
14 pub fn new(source_id: K, diff_id: K) -> Self {
15 Self {
16 source_id,
17 diff_id,
18 }
19 }
20}
21
22#[async_trait]
23impl<F, K> FrameProcessor<F> for TimestampDiffCalculator<K>
24where
25 K: Copy + Send,
26 F: FrameProperties<K, u128> + Send + 'static,
27{
28 async fn process(&mut self, mut frame_data: F) -> Option<F> {
29 let source_timestamp = frame_data.get(&self.source_id).unwrap();
30 frame_data.set(self.diff_id, now_timestamp() - source_timestamp);
31 Some(frame_data)
32 }
33}