block: qcow: Implement Deref for VecCache

Add Deref<Target = [T]> implementation for VecCache<T> to allow direct
slice operations without explicitly calling get_values(). This enables
cleaner code patterns like cache.iter() instead
of cache.get_values().iter().

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski 2025-12-08 15:48:02 +01:00 committed by Bo Chen
parent 9dc923f379
commit be5b14ef3a

View file

@ -7,7 +7,7 @@
use std::collections::HashMap;
use std::collections::hash_map::IterMut;
use std::io;
use std::ops::{Index, IndexMut};
use std::ops::{Deref, Index, IndexMut};
use std::slice::SliceIndex;
/// Trait that allows for checking if an implementor is dirty. Useful for types that are cached so
@ -85,6 +85,14 @@ impl<T: 'static + Copy + Default> IndexMut<usize> for VecCache<T> {
}
}
impl<T: 'static + Copy + Default> Deref for VecCache<T> {
type Target = [T];
fn deref(&self) -> &[T] {
&self.vec
}
}
#[derive(Clone, Debug)]
pub struct CacheMap<T: Cacheable> {
capacity: usize,