#[cfg(feature = "dev")]
use arbitrary::Arbitrary;
use crate::{groupings::Coordinatelike, prelude::*};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
#[cfg_attr(feature = "dev", derive(Arbitrary))]
pub struct Entry<const MCL: usize, const MCC: usize, const MPL: usize, N, S, PD> {
pub(crate) namespace_id: N,
pub(crate) subspace_id: S,
pub(crate) path: Path<MCL, MCC, MPL>,
pub(crate) timestamp: Timestamp,
pub(crate) payload_length: u64,
pub(crate) payload_digest: PD,
}
impl<const MCL: usize, const MCC: usize, const MPL: usize, N, S, PD>
Entry<MCL, MCC, MPL, N, S, PD>
{
pub fn builder() -> EntryBuilder<MCL, MCC, MPL, N, S, PD> {
EntryBuilder::create_empty()
}
pub fn prefilled_builder<E>(source: &E) -> EntryBuilder<MCL, MCC, MPL, N, S, PD>
where
E: Entrylike<MCL, MCC, MPL, N, S, PD>,
N: Clone,
S: Clone,
PD: Clone,
{
let mut builder = Self::builder();
builder
.namespace_id(source.wdm_namespace_id().clone())
.subspace_id(source.wdm_subspace_id().clone())
.path(source.wdm_path().clone())
.timestamp(source.wdm_timestamp())
.payload_digest(source.wdm_payload_digest().clone())
.payload_length(source.wdm_payload_length());
builder
}
}
impl<const MCL: usize, const MCC: usize, const MPL: usize, N, S, PD> Keylike<MCL, MCC, MPL, S>
for Entry<MCL, MCC, MPL, N, S, PD>
{
fn wdm_subspace_id(&self) -> &S {
&self.subspace_id
}
fn wdm_path(&self) -> &Path<MCL, MCC, MPL> {
&self.path
}
}
impl<const MCL: usize, const MCC: usize, const MPL: usize, N, S, PD>
Coordinatelike<MCL, MCC, MPL, S> for Entry<MCL, MCC, MPL, N, S, PD>
{
fn wdm_timestamp(&self) -> Timestamp {
self.timestamp
}
}
impl<const MCL: usize, const MCC: usize, const MPL: usize, N, S, PD>
Entrylike<MCL, MCC, MPL, N, S, PD> for Entry<MCL, MCC, MPL, N, S, PD>
{
fn wdm_namespace_id(&self) -> &N {
&self.namespace_id
}
fn wdm_payload_length(&self) -> u64 {
self.payload_length
}
fn wdm_payload_digest(&self) -> &PD {
&self.payload_digest
}
}