use core::cmp::Ordering;
use ufotofu::codec_prelude::*;
use willow_data_model::prelude as wdm;
use crate::prelude::*;
pub trait Entrylike:
Coordinatelike + Namespaced + wdm::Entrylike<MCL, MCC, MPL, NamespaceId, SubspaceId, PayloadDigest>
{
fn payload_length(&self) -> u64;
fn payload_digest(&self) -> &PayloadDigest;
}
impl<T> Entrylike for T
where
T: Coordinatelike
+ Namespaced
+ wdm::Entrylike<MCL, MCC, MPL, NamespaceId, SubspaceId, PayloadDigest>
+ ?Sized,
{
fn payload_length(&self) -> u64 {
self.wdm_payload_length()
}
fn payload_digest(&self) -> &PayloadDigest {
self.wdm_payload_digest()
}
}
pub trait EntrylikeExt:
wdm::EntrylikeExt<MCL, MCC, MPL, NamespaceId, SubspaceId, PayloadDigest>
{
fn entry_eq<OtherEntry>(&self, other: &OtherEntry) -> bool
where
OtherEntry: Entrylike,
{
self.wdm_entry_eq(other)
}
fn entry_ne<OtherEntry>(&self, other: &OtherEntry) -> bool
where
OtherEntry: Entrylike,
{
self.wdm_entry_ne(other)
}
fn cmp_recency<OtherEntry>(&self, other: &OtherEntry) -> Ordering
where
OtherEntry: Entrylike,
{
self.wdm_cmp_recency(other)
}
fn is_newer_than<OtherEntry>(&self, other: &OtherEntry) -> bool
where
OtherEntry: Entrylike,
{
self.wdm_is_newer_than(other)
}
fn is_older_than<OtherEntry>(&self, other: &OtherEntry) -> bool
where
OtherEntry: Entrylike,
{
self.wdm_is_older_than(other)
}
fn prunes<OtherEntry>(&self, other: &OtherEntry) -> bool
where
OtherEntry: Entrylike,
{
self.wdm_prunes(other)
}
fn is_pruned_by<OtherEntry>(&self, other: &OtherEntry) -> bool
where
OtherEntry: Entrylike,
Self: Sized,
{
self.wdm_is_pruned_by(other)
}
fn authorise(
&self,
write_capability: &WriteCapability,
secret: &SubspaceSecret,
) -> Result<AuthorisedEntry, DoesNotAuthorise> {
let authorisation_token =
AuthorisationToken::new_for_entry(self, write_capability, secret)?;
Ok(crate::authorisation::PossiblyAuthorisedEntry::new(
Entry::from_entrylike(self),
authorisation_token,
)
.into_authorised_entry().expect("AuthorisationToken::new_for_entry must produce an authorisation token that authorises the entry"))
}
async fn encode_entry<C>(&self, consumer: &mut C) -> Result<(), C::Error>
where
C: BulkConsumer<Item = u8> + ?Sized,
{
self.wdm_encode_entry(consumer).await
}
fn length_of_entry_encoding(&self) -> usize {
self.wdm_length_of_entry_encoding()
}
}
impl<E> EntrylikeExt for E where E: Entrylike + ?Sized {}