use crate::dds::{sampleinfo::*, traits::key::*};
#[derive(PartialEq, Debug)]
pub struct DataSample<D: Keyed> {
pub(crate) sample_info: SampleInfo,
pub(crate) value: std::result::Result<D, D::K>,
}
impl<D> DataSample<D>
where
D: Keyed,
{
pub(crate) fn new(sample_info: SampleInfo, value: std::result::Result<D, D::K>) -> Self {
Self { sample_info, value }
}
pub fn key(&self) -> D::K
where
<D as Keyed>::K: Key,
{
match &self.value {
Ok(d) => d.key(),
Err(k) => k.clone(),
}
}
pub fn value(&self) -> &Result<D, D::K> {
&self.value
}
pub fn into_value(self) -> Result<D, D::K> {
self.value
}
pub fn sample_info(&self) -> &SampleInfo {
&self.sample_info
}
pub fn sample_info_mut(&mut self) -> &mut SampleInfo {
&mut self.sample_info
}
}