plasma_prp/core/
keyed_object.rs1use std::io::Read;
9
10use anyhow::Result;
11
12use super::key::Key;
13use super::uoid::{Uoid, read_key_uoid};
14
15pub trait KeyedObject {
19 fn key(&self) -> &Key;
21
22 fn key_mut(&mut self) -> &mut Key;
24
25 fn set_key(&mut self, key: Key);
27}
28
29pub fn read_keyed_object(reader: &mut impl Read) -> Result<Option<Uoid>> {
32 read_key_uoid(reader)
33}
34
35#[derive(Debug, Clone, Default)]
37pub struct KeyedObjectData {
38 pub key: Key,
39}
40
41impl KeyedObjectData {
42 pub fn new() -> Self {
43 Self { key: Key::null() }
44 }
45
46 pub fn with_key(key: Key) -> Self {
47 Self { key }
48 }
49}
50
51impl KeyedObject for KeyedObjectData {
52 fn key(&self) -> &Key {
53 &self.key
54 }
55
56 fn key_mut(&mut self) -> &mut Key {
57 &mut self.key
58 }
59
60 fn set_key(&mut self, key: Key) {
61 self.key = key;
62 }
63}