use super::{FrameLease, PageObject};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct SwapToken(u64);
impl SwapToken {
pub const fn new(value: u64) -> Self {
Self(value)
}
pub const fn get(self) -> u64 {
self.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SwapError {
Unsupported,
Busy,
Io,
}
pub trait SwapProvider {
fn swap_out(&self, page: &PageObject) -> Result<SwapToken, SwapError>;
fn swap_in(&self, token: SwapToken, frame: FrameLease) -> Result<(), SwapError>;
}
#[derive(Debug, Default, Clone, Copy)]
pub struct UnsupportedSwap;
impl SwapProvider for UnsupportedSwap {
fn swap_out(&self, _page: &PageObject) -> Result<SwapToken, SwapError> {
Err(SwapError::Unsupported)
}
fn swap_in(&self, _token: SwapToken, _frame: FrameLease) -> Result<(), SwapError> {
Err(SwapError::Unsupported)
}
}