refactor: ByteOffset newtype for window/register/ring offsets; named virtio-gpu cmd fields
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user