use super::*;
use std::hash::Hash;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(test, derive(bolero::generator::TypeGenerator))]
pub struct Sample {
pub labels: LabelSetId,
pub stacktrace: StackTraceId,
}
impl Item for Sample {
type Id = SampleId;
}
impl Sample {
pub fn new(labels: LabelSetId, stacktrace: StackTraceId) -> Self {
Self { labels, stacktrace }
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[repr(C)]
pub struct SampleId(u32);
impl SampleId {
#[inline]
pub fn to_offset(&self) -> usize {
self.0 as usize
}
}
impl Id for SampleId {
type RawId = usize;
fn from_offset(inner: usize) -> Self {
#[allow(clippy::expect_used)]
let index: u32 = inner.try_into().expect("SampleId to fit into a u32");
Self(index)
}
fn to_raw_id(&self) -> Self::RawId {
self.0 as Self::RawId
}
}