#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VolumeRole {
Primary,
ExtendedContainer,
Logical,
Protective,
Metadata,
Unknown,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct VolumeSpan {
pub byte_offset: u64,
pub byte_size: u64,
}
impl VolumeSpan {
pub const fn new(byte_offset: u64, byte_size: u64) -> Self {
Self {
byte_offset,
byte_size,
}
}
pub fn end_offset(self) -> Option<u64> {
self.byte_offset.checked_add(self.byte_size)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VolumeRecord {
pub index: usize,
pub span: VolumeSpan,
pub name: Option<String>,
pub role: VolumeRole,
}
impl VolumeRecord {
pub const fn new(index: usize, span: VolumeSpan, role: VolumeRole) -> Self {
Self {
index,
span,
name: None,
role,
}
}
pub fn with_name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn volume_span_reports_end_offset() {
let span = VolumeSpan::new(512, 2048);
assert_eq!(span.end_offset(), Some(2560));
}
#[test]
fn volume_record_accepts_names() {
let record =
VolumeRecord::new(1, VolumeSpan::new(0, 4096), VolumeRole::Primary).with_name("system");
assert_eq!(record.name.as_deref(), Some("system"));
}
}