computer: fix stateful

This commit is contained in:
nym21
2025-07-17 11:35:40 +02:00
parent a0cfc1be2b
commit c07e66c086
16 changed files with 340 additions and 105 deletions

View File

@@ -19,6 +19,21 @@ impl AnyAddressIndex {
}
}
impl From<LoadedAddressIndex> for AnyAddressIndex {
fn from(value: LoadedAddressIndex) -> Self {
if u32::from(value) >= MIN_EMPTY_INDEX {
panic!("")
}
Self(*value)
}
}
impl From<EmptyAddressIndex> for AnyAddressIndex {
fn from(value: EmptyAddressIndex) -> Self {
Self(*value + MIN_EMPTY_INDEX)
}
}
impl Serialize for AnyAddressIndex {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -38,9 +53,7 @@ impl From<AnyAddressIndex> for AnyAddressDataIndexEnum {
fn from(value: AnyAddressIndex) -> Self {
let uvalue = u32::from(value.0);
if uvalue >= MIN_EMPTY_INDEX {
Self::Empty(EmptyAddressIndex::from(TypeIndex::from(
uvalue - MIN_EMPTY_INDEX,
)))
Self::Empty(EmptyAddressIndex::from(uvalue - MIN_EMPTY_INDEX))
} else {
Self::Loaded(LoadedAddressIndex::from(value.0))
}

View File

@@ -1,5 +1,6 @@
use std::ops::Add;
use derive_deref::Deref;
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -7,13 +8,14 @@ use crate::{CheckedSub, Printable, TypeIndex};
#[derive(
Debug,
Default,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Clone,
Copy,
Default,
Deref,
FromBytes,
Immutable,
IntoBytes,
@@ -33,6 +35,11 @@ impl From<usize> for EmptyAddressIndex {
Self(TypeIndex::from(value))
}
}
impl From<u32> for EmptyAddressIndex {
fn from(value: u32) -> Self {
Self(TypeIndex::from(value))
}
}
impl From<EmptyAddressIndex> for usize {
fn from(value: EmptyAddressIndex) -> Self {

View File

@@ -1,5 +1,6 @@
use std::ops::Add;
use derive_deref::Deref;
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -13,6 +14,7 @@ use crate::{CheckedSub, Printable, TypeIndex};
Ord,
Clone,
Copy,
Deref,
Default,
FromBytes,
Immutable,
@@ -38,6 +40,11 @@ impl From<LoadedAddressIndex> for usize {
usize::from(value.0)
}
}
impl From<LoadedAddressIndex> for u32 {
fn from(value: LoadedAddressIndex) -> Self {
u32::from(value.0)
}
}
impl Add<usize> for LoadedAddressIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {

View File

@@ -73,6 +73,12 @@ impl From<TypeIndex> for usize {
}
}
impl Add<u32> for TypeIndex {
type Output = Self;
fn add(self, rhs: u32) -> Self::Output {
Self(self.0 + rhs)
}
}
impl Add<usize> for TypeIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {