use crate::io::io_request_data::IoRequestData;
use std::borrow::Borrow;
use std::time::Instant;
#[derive(Clone)]
pub(crate) struct TimeBoundedIoTask {
deadline: Instant,
user_data: u64,
}
impl TimeBoundedIoTask {
#[inline(always)]
pub(crate) fn new(io_request_data: &IoRequestData, deadline: Instant) -> Self {
Self {
deadline,
user_data: std::ptr::from_ref(io_request_data) as u64,
}
}
#[inline(always)]
pub(crate) fn user_data(&self) -> u64 {
self.user_data
}
#[inline(always)]
pub(crate) fn deadline(&self) -> Instant {
self.deadline
}
}
impl PartialEq for TimeBoundedIoTask {
#[inline(always)]
fn eq(&self, other: &Self) -> bool {
self.deadline == other.deadline
}
}
impl PartialOrd for TimeBoundedIoTask {
#[inline(always)]
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Eq for TimeBoundedIoTask {}
impl Ord for TimeBoundedIoTask {
#[inline(always)]
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.deadline.cmp(&other.deadline)
}
}
impl Borrow<Instant> for TimeBoundedIoTask {
#[inline(always)]
fn borrow(&self) -> &Instant {
&self.deadline
}
}