aboutsummaryrefslogtreecommitdiff
path: root/common/object/src/lib.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-01-06 02:53:21 +0100
committermetamuffin <metamuffin@disroot.org>2026-01-06 02:53:21 +0100
commitbb7aa0604d1928ec435e97f6e58521597bc61c3b (patch)
treef12f1b876c7876a79736f88aedeb4290896170d9 /common/object/src/lib.rs
parentce5ed3f54e873fff9135313a4ed9fa6656caf741 (diff)
downloadjellything-bb7aa0604d1928ec435e97f6e58521597bc61c3b.tar
jellything-bb7aa0604d1928ec435e97f6e58521597bc61c3b.tar.bz2
jellything-bb7aa0604d1928ec435e97f6e58521597bc61c3b.tar.zst
impl value for object
Diffstat (limited to 'common/object/src/lib.rs')
-rw-r--r--common/object/src/lib.rs55
1 files changed, 3 insertions, 52 deletions
diff --git a/common/object/src/lib.rs b/common/object/src/lib.rs
index 33d38d1..90ddef5 100644
--- a/common/object/src/lib.rs
+++ b/common/object/src/lib.rs
@@ -4,6 +4,9 @@
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
+mod value;
+pub use value::*;
+
use std::marker::PhantomData;
#[repr(transparent)]
@@ -78,55 +81,3 @@ impl<'a> Object<'a> {
}
}
}
-
-pub trait Value<'a>: Sized {
- const ALIGNED: bool;
- fn load_aligned(buf: &'a [u32]) -> Option<Self> {
- let _ = buf;
- None
- }
- fn load_unaligned(buf: &'a [u8]) -> Option<Self> {
- let _ = buf;
- None
- }
- fn store(&self, buf: &mut Vec<u8>);
- fn size(&self) -> usize;
-}
-impl<'a> Value<'a> for &'a str {
- const ALIGNED: bool = false;
- fn load_unaligned(buf: &'a [u8]) -> Option<Self> {
- str::from_utf8(buf).ok()
- }
- fn store(&self, buf: &mut Vec<u8>) {
- buf.extend(self.as_bytes());
- }
- fn size(&self) -> usize {
- self.len()
- }
-}
-impl Value<'_> for u32 {
- const ALIGNED: bool = false;
- fn load_aligned(buf: &[u32]) -> Option<Self> {
- buf.get(0).copied()
- }
- fn store(&self, buf: &mut Vec<u8>) {
- buf.extend(self.to_ne_bytes());
- }
- fn size(&self) -> usize {
- 4
- }
-}
-impl Value<'_> for u64 {
- const ALIGNED: bool = false;
- fn load_aligned(buf: &[u32]) -> Option<Self> {
- let hi = *buf.get(0)? as u64;
- let lo = *buf.get(1)? as u64;
- Some(hi << 32 | lo)
- }
- fn store(&self, buf: &mut Vec<u8>) {
- buf.extend(self.to_ne_bytes());
- }
- fn size(&self) -> usize {
- 8
- }
-}