use {
crate::{ContentHash, Ident, database::PartitionKey},
std::marker::PhantomData,
};
#[derive(Debug)]
pub struct RecordHandle<P: PartitionKey> {
hash: ContentHash,
_marker: PhantomData<P>,
}
impl<P: PartitionKey> RecordHandle<P> {
#[inline]
pub fn new(hash: ContentHash) -> Self {
Self {
hash,
_marker: PhantomData,
}
}
#[inline]
pub fn partition_key() -> Ident {
P::KEY
}
#[inline]
pub fn content_hash(&self) -> ContentHash {
self.hash
}
}
impl<P: PartitionKey> Clone for RecordHandle<P> {
fn clone(&self) -> Self {
*self
}
}
impl<P: PartitionKey> Copy for RecordHandle<P> {}
impl<P: PartitionKey> PartialEq for RecordHandle<P> {
fn eq(&self, other: &Self) -> bool {
self.hash == other.hash
}
}
impl<P: PartitionKey> Eq for RecordHandle<P> {}
impl<P: PartitionKey> std::hash::Hash for RecordHandle<P> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.hash.hash(state);
}
}
impl<P: PartitionKey> PartialOrd for RecordHandle<P> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl<P: PartitionKey> Ord for RecordHandle<P> {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.hash.cmp(&other.hash)
}
}