use std::marker::PhantomData;
use std::os::unix::io::RawFd;
use std::pin::Pin;
use crate::operation::{OperationState, OperationType};
use crate::registry::{FixedFile, RegisteredBuffer, RegisteredFd};
#[derive(Debug)]
pub enum BufferType<'buf> {
None,
Pinned(Pin<&'buf mut [u8]>),
Registered(RegisteredBuffer),
Vectored(Vec<Pin<&'buf mut [u8]>>),
}
#[derive(Debug)]
pub enum FdType {
Raw(RawFd),
Registered(RegisteredFd),
Fixed(FixedFile),
}
#[derive(Debug)]
pub struct Operation<'ring, 'buf, S> {
pub(crate) ring: PhantomData<&'ring ()>,
pub(crate) buffer: BufferType<'buf>,
pub(crate) fd: FdType,
pub(crate) offset: u64,
pub(crate) op_type: OperationType,
pub(crate) state: S,
}
impl<'ring, 'buf, S: OperationState> Operation<'ring, 'buf, S> {
#[inline]
pub fn get_type(&self) -> OperationType {
self.op_type
}
#[inline]
pub fn has_buffer(&self) -> bool {
!matches!(self.buffer, BufferType::None)
}
#[inline]
pub fn get_fd(&self) -> RawFd {
match &self.fd {
FdType::Raw(fd) => *fd,
FdType::Registered(reg_fd) => reg_fd.raw_fd(),
FdType::Fixed(fixed_file) => fixed_file.raw_fd(),
}
}
}