Skip to main content

ReOpenFile

Struct ReOpenFile 

Source
pub struct ReOpenFile { /* private fields */ }
Expand description

An owned, marshalable parameter set for ReOpenFile.

§Example

A read-only handle to a file that was opened for writing, the same file through a new handle that says what it wants anew:

use std::fs;

use windows_namespace_request_sys::reopen::ReOpenFile;
use windows_sys::Win32::Storage::FileSystem::{
    FILE_GENERIC_READ, FILE_SHARE_DELETE, FILE_SHARE_READ, FILE_SHARE_WRITE,
};

let path = std::env::temp_dir().join(format!("wnrs-reopen-{}.tmp", std::process::id()));
fs::write(&path, b"example")?;
let original = fs::OpenOptions::new().read(true).write(true).open(&path)?;

let request = ReOpenFile::new(original)
    .with_desired_access(FILE_GENERIC_READ)
    .with_share_mode(FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE);
let reopened = fs::File::from(request.perform()?);

assert_eq!(reopened.metadata()?.len(), b"example".len() as u64);

Implementations§

Source§

impl ReOpenFile

Source

pub fn new(original: impl Into<SharedHandle>) -> Self

Begins a request to reopen the file, directory or volume original names.

The request holds original as one more holder of it. The remaining parameters start at “the caller said nothing” and are set explicitly.

Source

pub fn with_desired_access(self, desired_access: u32) -> Self

Sets dwDesiredAccess.

Source

pub fn with_share_mode(self, share_mode: FILE_SHARE_MODE) -> Self

Sets dwShareMode.

Source

pub fn with_flags_and_attributes( self, flags_and_attributes: FILE_FLAGS_AND_ATTRIBUTES, ) -> Self

Sets dwFlagsAndAttributes, carried verbatim as in crate::open::OpenFile.

Source

pub fn original(&self) -> &SharedHandle

The handle being reopened, shared with its other holders.

Source

pub fn desired_access(&self) -> u32

The requested access mask.

Source

pub fn share_mode(&self) -> FILE_SHARE_MODE

The requested share mode.

Source

pub fn flags_and_attributes(&self) -> FILE_FLAGS_AND_ATTRIBUTES

The requested flags and attributes.

Source

pub fn perform(&self) -> Outcome<OwnedHandle>

Performs the reopen on the calling thread.

The handle comes back owned and is a new handle each time, however often the request is performed.

§Errors

Returns the raw Win32 code, unaltered. An access or sharing that conflicts with a previous open still open is a sharing violation, which is the kernel’s error and passes through.

Trait Implementations§

Source§

impl Clone for ReOpenFile

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ReOpenFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Request for ReOpenFile

Source§

type Error = Win32Error

How performing it can fail. Read more
Source§

type Output = OwnedHandle

What performing the request produces.
Source§

fn perform(&self) -> Outcome<OwnedHandle>

Performs the request on the calling thread. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.