use std::io::Read;
use anyhow::Result;
use super::key::Key;
use super::uoid::{Uoid, read_key_uoid};
pub trait KeyedObject {
fn key(&self) -> &Key;
fn key_mut(&mut self) -> &mut Key;
fn set_key(&mut self, key: Key);
}
pub fn read_keyed_object(reader: &mut impl Read) -> Result<Option<Uoid>> {
read_key_uoid(reader)
}
#[derive(Debug, Clone, Default)]
pub struct KeyedObjectData {
pub key: Key,
}
impl KeyedObjectData {
pub fn new() -> Self {
Self { key: Key::null() }
}
pub fn with_key(key: Key) -> Self {
Self { key }
}
}
impl KeyedObject for KeyedObjectData {
fn key(&self) -> &Key {
&self.key
}
fn key_mut(&mut self) -> &mut Key {
&mut self.key
}
fn set_key(&mut self, key: Key) {
self.key = key;
}
}