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:
parent
9dc923f379
commit
be5b14ef3a
1 changed files with 9 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue