Skip to main content

OpenFileByIdentifier

Struct OpenFileByIdentifier 

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

An owned, marshalable parameter set for OpenFileById.

§Example

use std::fs;

use windows_namespace_request_sys::open_by_id::{FileIdentifier, OpenFileByIdentifier};
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-byid-{}.tmp", std::process::id()));
fs::write(&path, b"example")?;
let file = fs::File::open(&path)?;

// Any open handle on the same volume will do as the hint; it is never the
// object being reopened. The request holds it, shared.
let request = OpenFileByIdentifier::new(file, FileIdentifier::FileId(0))
    .with_desired_access(FILE_GENERIC_READ)
    .with_share_mode(FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE);

assert_eq!(request.identifier(), FileIdentifier::FileId(0));

Implementations§

Source§

impl OpenFileByIdentifier

Source

pub fn new( volume_hint: impl Into<SharedHandle>, identifier: FileIdentifier, ) -> Self

Begins a request to reopen identifier, using volume_hint to name the volume it lives on.

As with crate::open::OpenFile, the remaining parameters start at “the caller said nothing” and are set explicitly. There is no creation disposition to set: OpenFileById has none, which is one of the reasons this is a separate entry rather than a variant. The request holds volume_hint as one more holder of it.

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_security(self, security: Option<SecurityAttributes>) -> Self

Sets lpSecurityAttributes from an already-captured value.

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 volume_hint(&self) -> &SharedHandle

The volume-hint handle, shared with its other holders.

Source

pub fn identifier(&self) -> FileIdentifier

The identifier this request will reopen.

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 security(&self) -> Option<&SecurityAttributes>

The captured security attributes, if any were supplied.

Source

pub fn flags_and_attributes(&self) -> FILE_FLAGS_AND_ATTRIBUTES

The requested flags and attributes.

Source

pub fn try_clone(&self) -> Result<Self, SecurityCaptureError>

Copies the request, sharing the volume-hint handle.

Not Clone, for the same reason crate::open::OpenFile::try_clone is not: copying the security attributes it may own is fallible. The hint is shared, not duplicated (D-32 in the crate’s DESIGN-NOTES.md), so it cannot fail.

§Errors

Returns SecurityAttributes::try_clone’s error when the memory for the security attributes cannot be allocated. A request without them cannot fail.

Source

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

Performs the open on the calling thread.

The handle comes back plain and unassociated, as with every other handle-producing entry.

§Errors

Returns the raw Win32 code, unaltered. ERROR_INVALID_PARAMETER here most often means the identified object no longer exists, but nothing in this crate infers that on the caller’s behalf.

Trait Implementations§

Source§

impl Debug for OpenFileByIdentifier

Source§

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

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

impl Request for OpenFileByIdentifier

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> 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, 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.