use std::{fmt::Debug, io};
use super::*;
#[repr(transparent)]
pub struct Extra(pub(super) imp::Extra);
impl Debug for Extra {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Extra").field("sys", &"<...>").finish()
}
}
impl<I: Into<imp::Extra>> From<I> for Extra {
fn from(inner: I) -> Self {
Self::new(inner.into())
}
}
impl Extra {
pub(super) fn new(inner: imp::Extra) -> Self {
Self(inner)
}
pub fn with_personality(mut self, personality: u16) -> Self {
self.set_personality(personality);
self
}
pub fn set_personality(&mut self, personality: u16) {
#[cfg(io_uring)]
if let Some(extra) = self.try_as_iour_mut() {
extra.set_personality(personality);
}
#[cfg(not(io_uring))]
let _ = personality;
}
pub fn get_personality(&self) -> Option<u16> {
#[cfg(io_uring)]
if let Some(extra) = self.try_as_iour() {
extra.get_personality()
} else {
None
}
#[cfg(not(io_uring))]
None
}
pub fn buffer_id(&self) -> io::Result<u16> {
#[cfg(io_uring)]
{
if let Some(extra) = self.try_as_iour() {
extra
.buffer_id()
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "flags are invalid"))
} else {
Ok(0)
}
}
#[cfg(not(io_uring))]
{
Ok(0)
}
}
}