libdd_profiling/internal/
sample.rs1use super::*;
5use std::hash::Hash;
6
7#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
8#[cfg_attr(test, derive(bolero::generator::TypeGenerator))]
9pub struct Sample {
10 pub labels: LabelSetId,
13 pub stacktrace: StackTraceId,
14}
15
16impl Item for Sample {
17 type Id = SampleId;
18}
19
20impl Sample {
21 pub fn new(labels: LabelSetId, stacktrace: StackTraceId) -> Self {
22 Self { labels, stacktrace }
23 }
24}
25
26#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
27#[repr(C)]
28pub struct SampleId(u32);
29
30impl SampleId {
31 #[inline]
32 pub fn to_offset(&self) -> usize {
33 self.0 as usize
34 }
35}
36
37impl Id for SampleId {
38 type RawId = usize;
39
40 fn from_offset(inner: usize) -> Self {
41 #[allow(clippy::expect_used)]
42 let index: u32 = inner.try_into().expect("SampleId to fit into a u32");
43 Self(index)
44 }
45
46 fn to_raw_id(&self) -> Self::RawId {
47 self.0 as Self::RawId
48 }
49}