Struct winsafe::FileMapped
source · pub struct FileMapped { /* private fields */ }
Available on crate feature
kernel
only.Expand description
Manages an HFILEMAP
handle, which provides
memory-mapped file operations, including read/write through slices. It is
closed automatically when the object goes out of scope.
§Examples
Usually the fastest way to read a file as string is by memory-mapping it, like:
use winsafe::{self as w, prelude::*};
let f = w::FileMapped::open(
"C:\\Temp\\foo.txt",
w::FileAccess::ExistingReadOnly,
)?;
let raw_bytes = f.as_slice();
let text = w::WString::parse(raw_bytes)?.to_string();
Implementations§
source§impl FileMapped
impl FileMapped
sourcepub fn open(file_path: &str, access: FileAccess) -> SysResult<Self>
pub fn open(file_path: &str, access: FileAccess) -> SysResult<Self>
Opens a file with the desired access, then map its contents in memory.
sourcepub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Returns a mutable slice to the mapped memory.
sourcepub fn times(&self) -> SysResult<(SYSTEMTIME, SYSTEMTIME)>
pub fn times(&self) -> SysResult<(SYSTEMTIME, SYSTEMTIME)>
Returns the creation and last write times of the file, in the current time zone.
Auto Trait Implementations§
impl Freeze for FileMapped
impl RefUnwindSafe for FileMapped
impl Send for FileMapped
impl !Sync for FileMapped
impl Unpin for FileMapped
impl UnwindSafe for FileMapped
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more