refactor: ByteOffset newtype for window/register/ring offsets; named virtio-gpu cmd fields

This commit is contained in:
2026-10-27 21:52:33 +01:00
parent 842d14987c
commit 7b8258b231
13 changed files with 145 additions and 93 deletions

View File

@@ -68,3 +68,29 @@ impl DataRef {
}
}
}
/// A position in bytes inside a mapped window: a device register, a field
/// of a ring or command. Adding a byte count moves it along.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct ByteOffset(usize);
impl ByteOffset {
pub const ZERO: Self = Self(0);
pub const fn new(bytes: usize) -> Self {
Self(bytes)
}
pub const fn raw(&self) -> usize {
self.0
}
}
impl core::ops::Add<usize> for ByteOffset {
type Output = Self;
/// Saturates: an offset past the end is refused where it is used.
fn add(self, bytes: usize) -> Self {
Self(self.0.saturating_add(bytes))
}
}