cloud_filter/
utility.rs

1use std::{future::Future, pin::Pin};
2
3use windows::core::{self, HSTRING};
4
5use crate::sealed;
6
7pub use nt_time::FileTime;
8
9// TODO: add something to convert an Option<T> to a *const T and *mut T
10
11pub(crate) trait ToHString
12where
13    Self: AsRef<[u16]>,
14{
15    /// Converts a 16-bit buffer to a Windows reference-counted [HSTRING][windows::core::HSTRING].
16    ///
17    /// # Panics
18    ///
19    /// Panics if [HeapAlloc](https://docs.microsoft.com/en-us/windows/win32/api/heapapi/nf-heapapi-heapalloc) fails.
20    fn to_hstring(&self) -> HSTRING {
21        HSTRING::from_wide(self.as_ref()).unwrap()
22    }
23}
24
25impl<T: AsRef<[u16]>> ToHString for T {}
26
27/// A trait for types that can read data from a file-like object at a specific offset.
28///
29/// This is a low-level interface that is used by Cloud Filter to implement the
30/// [CfExecute](https://docs.microsoft.com/en-us/windows/win32/api/cfapi/nf-cfapi-cfexecute)
31/// function's `CF_OPERATION_TYPE_RETRIEVE_DATA` operation.
32///
33/// You should not need to implement this trait yourself, but rather use the
34/// [utility::ReadAt](crate::utility::ReadAt) trait as a bound for your argument.
35pub trait ReadAt: sealed::Sealed {
36    fn read_at(&self, buf: &mut [u8], offset: u64) -> core::Result<u64>;
37}
38
39/// A trait for types that can write data to a file-like object at a specific offset.
40///
41/// This is a low-level interface that is used by Cloud Filter to implement the
42/// [CfExecute](https://docs.microsoft.com/en-us/windows/win32/api/cfapi/nf-cfapi-cfexecute)
43/// function's `CF_OPERATION_TYPE_TRANSFER_DATA` operation.
44///
45/// You should not need to implement this trait yourself, but rather use the
46/// [utility::WriteAt](crate::utility::WriteAt) trait as a bound for your argument.
47pub trait WriteAt: sealed::Sealed {
48    fn write_at(&self, buf: &[u8], offset: u64) -> core::Result<()>;
49}
50
51pub(crate) type LocalBoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;