use std::os::unix::io::RawFd;
use std::pin::Pin;
use super::core::{BufferType, FdType, Operation};
use crate::operation::{Completed, OperationType};
impl<'ring, 'buf, T> Operation<'ring, 'buf, Completed<T>> {
pub fn into_result(self) -> (T, BufferType<'buf>) {
(self.state.result, self.buffer)
}
pub fn into_result_with_buffer(self) -> (T, Option<Pin<&'buf mut [u8]>>) {
let (result, buffer_type) = self.into_result();
let buffer = match buffer_type {
BufferType::Pinned(buf) => Some(buf),
_ => None,
};
(result, buffer)
}
pub fn into_result_with_vectored_buffers(self) -> (T, Option<Vec<Pin<&'buf mut [u8]>>>) {
let (result, buffer_type) = self.into_result();
let buffers = match buffer_type {
BufferType::Vectored(bufs) => Some(bufs),
_ => None,
};
(result, buffers)
}
#[inline]
pub fn result(&self) -> &T {
&self.state.result
}
#[inline]
pub fn 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(),
}
}
#[inline]
pub fn offset(&self) -> u64 {
self.offset
}
#[inline]
pub fn op_type(&self) -> OperationType {
self.op_type
}
}