diff --git a/src/page/flush.rs b/src/page/flush.rs index 9aae51f599..5dedf6afae 100644 --- a/src/page/flush.rs +++ b/src/page/flush.rs @@ -8,6 +8,10 @@ use crate::{ VirtualAddress, }; +pub trait Flusher { + fn consume(&mut self, flush: PageFlush); +} + #[must_use = "The page table must be flushed, or the changes unsafely ignored"] pub struct PageFlush { virt: VirtualAddress, @@ -43,10 +47,6 @@ impl PageFlushAll { } } - pub fn consume(&self, flush: PageFlush) { - unsafe { flush.ignore(); } - } - pub fn flush(self) { unsafe { A::invalidate_all(); } } @@ -55,3 +55,16 @@ impl PageFlushAll { mem::forget(self); } } +impl Flusher for PageFlushAll { + fn consume(&mut self, flush: PageFlush) { + unsafe { flush.ignore(); } + } +} +impl + ?Sized> Flusher for &mut T { + fn consume(&mut self, flush: PageFlush) { + >::consume(self, flush) + } +} +impl Flusher for () { + fn consume(&mut self, _: PageFlush) {} +}