use crate::ObservedSync as _;
use std::fs::File;
use std::io;
use super::FileIdentity;
#[cfg(windows)]
#[derive(Debug)]
pub struct WindowsCasWriter {
pub(super) file: File,
pub(super) identity: FileIdentity,
}
#[cfg(windows)]
impl io::Write for WindowsCasWriter {
fn write(&mut self, buffer: &[u8]) -> io::Result<usize> {
io::Write::write(&mut self.file, buffer)
}
fn flush(&mut self) -> io::Result<()> {
io::Write::flush(&mut self.file)
}
}
#[cfg(windows)]
impl io::Read for WindowsCasWriter {
fn read(&mut self, buffer: &mut [u8]) -> io::Result<usize> {
io::Read::read(&mut self.file, buffer)
}
}
#[cfg(windows)]
impl io::Seek for WindowsCasWriter {
fn seek(&mut self, position: io::SeekFrom) -> io::Result<u64> {
io::Seek::seek(&mut self.file, position)
}
}
#[cfg(windows)]
impl WindowsCasWriter {
#[doc(hidden)]
#[must_use]
pub fn as_file(&self) -> &File {
&self.file
}
pub fn sync_all(&self) -> io::Result<()> {
self.file.observed_sync_all()
}
#[must_use]
pub fn identity(&self) -> FileIdentity {
self.identity
}
}
#[cfg(windows)]
impl crate::ObservedSync for WindowsCasWriter {
fn observed_sync_all(&self) -> io::Result<()> {
self.sync_all()
}
fn observed_sync_data(&self) -> io::Result<()> {
self.file.observed_sync_data()
}
}
#[cfg(windows)]
#[derive(Debug)]
pub struct WindowsSealedCasFile(pub(super) File);
#[cfg(windows)]
impl WindowsSealedCasFile {
#[must_use]
pub fn into_file(self) -> File {
self.0
}
}
#[cfg(windows)]
#[derive(Debug)]
pub struct WindowsLegacyCasAdopter {
pub(super) file: File,
pub(super) identity: FileIdentity,
}
#[cfg(windows)]
impl io::Read for WindowsLegacyCasAdopter {
fn read(&mut self, buffer: &mut [u8]) -> io::Result<usize> {
io::Read::read(&mut self.file, buffer)
}
}
#[cfg(windows)]
impl io::Seek for WindowsLegacyCasAdopter {
fn seek(&mut self, position: io::SeekFrom) -> io::Result<u64> {
io::Seek::seek(&mut self.file, position)
}
}
#[cfg(test)]
mod tests;