aboutsummaryrefslogtreecommitdiff
path: root/common/object/src/value.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-01-16 04:21:06 +0100
committermetamuffin <metamuffin@disroot.org>2026-01-16 04:21:06 +0100
commit9b5d11a2a39e0030ce4eeab8905972f9472c7d27 (patch)
tree90f6e68f8595309b54bb014db509cd709234c9cc /common/object/src/value.rs
parentc836b650eaf4ba33b1cfd2b475971b3ccc9f69b7 (diff)
downloadjellything-9b5d11a2a39e0030ce4eeab8905972f9472c7d27.tar
jellything-9b5d11a2a39e0030ce4eeab8905972f9472c7d27.tar.bz2
jellything-9b5d11a2a39e0030ce4eeab8905972f9472c7d27.tar.zst
object extend method
Diffstat (limited to 'common/object/src/value.rs')
-rw-r--r--common/object/src/value.rs53
1 files changed, 52 insertions, 1 deletions
diff --git a/common/object/src/value.rs b/common/object/src/value.rs
index aad6101..83878d3 100644
--- a/common/object/src/value.rs
+++ b/common/object/src/value.rs
@@ -4,7 +4,7 @@
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
-use crate::{Object, ObjectBuffer};
+use crate::{Object, ObjectBuffer, Tag};
pub trait Value<'a>: ValueStore + Sized {
const ALIGNED: bool;
@@ -57,6 +57,23 @@ impl ValueStore for u32 {
4
}
}
+impl Value<'_> for Tag {
+ const ALIGNED: bool = true;
+ fn load_aligned(buf: &[u32]) -> Option<Self> {
+ buf.get(0).copied().map(u32::from_be).map(Tag)
+ }
+}
+impl ValueStore for Tag {
+ fn is_aligned(&self) -> bool {
+ true
+ }
+ fn store_aligned(&self, buf: &mut Vec<u32>) {
+ buf.push(self.0.to_be());
+ }
+ fn size(&self) -> usize {
+ 4
+ }
+}
impl Value<'_> for u64 {
const ALIGNED: bool = false;
fn load_aligned(buf: &[u32]) -> Option<Self> {
@@ -77,6 +94,40 @@ impl ValueStore for u64 {
8
}
}
+impl Value<'_> for f64 {
+ const ALIGNED: bool = false;
+ fn load_aligned(buf: &[u32]) -> Option<Self> {
+ u32::load_aligned(buf).map(|x| x as f64)
+ }
+}
+impl ValueStore for f64 {
+ fn is_aligned(&self) -> bool {
+ true
+ }
+ fn store_aligned(&self, buf: &mut Vec<u32>) {
+ (*self as u64).store_aligned(buf);
+ }
+ fn size(&self) -> usize {
+ 8
+ }
+}
+impl Value<'_> for i64 {
+ const ALIGNED: bool = false;
+ fn load_aligned(buf: &[u32]) -> Option<Self> {
+ u32::load_aligned(buf).map(|x| x as i64)
+ }
+}
+impl ValueStore for i64 {
+ fn is_aligned(&self) -> bool {
+ true
+ }
+ fn store_aligned(&self, buf: &mut Vec<u32>) {
+ (*self as u64).store_aligned(buf);
+ }
+ fn size(&self) -> usize {
+ 8
+ }
+}
impl<'a> Value<'a> for Object<'a> {
const ALIGNED: bool = true;
fn load_aligned(buf: &'a [u32]) -> Option<Self> {