use super::ResolvedLayout;
use alloc::string::String;
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct GrownPartition {
pub name: String,
pub size_at_minimum: u64,
pub size: u64,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MovedPartition {
pub name: String,
pub offset_at_minimum: u64,
pub offset: u64,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct LayoutChanges {
pub grown: Vec<GrownPartition>,
pub moved: Vec<MovedPartition>,
}
impl LayoutChanges {
pub fn is_empty(&self) -> bool {
self.grown.is_empty() && self.moved.is_empty()
}
}
impl ResolvedLayout {
pub fn changes_from(&self, minimum: &ResolvedLayout) -> LayoutChanges {
let mut changes = LayoutChanges::default();
for partition in &self.partitions {
let name = &partition.definition.name;
let Some(base) = minimum.partition(name) else {
continue;
};
if partition.size != base.size {
changes.grown.push(GrownPartition {
name: name.clone(),
size_at_minimum: base.size,
size: partition.size,
});
}
if partition.offset != base.offset {
changes.moved.push(MovedPartition {
name: name.clone(),
offset_at_minimum: base.offset,
offset: partition.offset,
});
}
}
changes
}
}