mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user