use std::mem::MaybeUninit;
use windows_sys::Win32::Storage::FileSystem::{
BY_HANDLE_FILE_INFORMATION, GetFileInformationByHandle,
};
use win_shared_os_owned_handle::SharedHandle;
use crate::handle::SharedRaw;
use crate::outcome::{Outcome, perform_bool};
#[derive(Clone, Debug)]
#[must_use = "an unperformed request queries nothing"]
pub struct QueryFileInformationByHandle {
handle: SharedHandle,
}
impl QueryFileInformationByHandle {
pub fn new(handle: impl Into<SharedHandle>) -> Self {
Self {
handle: handle.into(),
}
}
pub fn handle(&self) -> &SharedHandle {
&self.handle
}
pub fn perform(&self) -> Outcome<BY_HANDLE_FILE_INFORMATION> {
let mut information = MaybeUninit::<BY_HANDLE_FILE_INFORMATION>::uninit();
perform_bool(|| {
unsafe { GetFileInformationByHandle(self.handle.raw(), information.as_mut_ptr()) }
})?;
Ok(unsafe { information.assume_init() })
}
}
impl crate::request::Request for QueryFileInformationByHandle {
type Error = crate::Win32Error;
type Output = BY_HANDLE_FILE_INFORMATION;
fn perform(&self) -> Outcome<BY_HANDLE_FILE_INFORMATION> {
Self::perform(self)
}
}
#[cfg(test)]
mod tests;