Skip to main content

Captured

Enum Captured 

Source
pub enum Captured<T> {
    NotCaptured,
    Absent,
    Present(T),
}
Expand description

What a capture produced for one aspect.

§Why this is not Option

Not captured and captured, and the thread had none are different facts with the same observable outcome, and only one of them is a decision.

Take impersonation. If the aspect was left out of the capture set, the worker runs under the process identity. If it was captured and the calling thread had no token, the worker also runs under the process identity. A caller reading back an Option::None cannot tell which happened – so an omission becomes indistinguishable from a deliberate statement about what the work should run as, and nobody can later reconstruct which one it was.

The shape is uniform across aspects even where Absent is unreachable, because a per-aspect shape would make every consumer remember which aspects can be absent.

§Example

use windows_thread_ambient_sys::Captured;

let omitted: Captured<u32> = Captured::NotCaptured;
let asked_and_empty: Captured<u32> = Captured::Absent;

// Both yield nothing, which is what `Option` would collapse them to...
assert_eq!(omitted.present(), None);
assert_eq!(asked_and_empty.present(), None);

// ...but only one of them is a decision, and that stays recoverable.
assert!(!omitted.was_captured());
assert!(asked_and_empty.was_captured());

Variants§

§

NotCaptured

The aspect was not in the capture set, so nothing was read and the target thread’s own value is left alone.

§

Absent

The aspect was captured, and the calling thread had no value for it.

§

Present(T)

The aspect was captured.

Implementations§

Source§

impl<T> Captured<T>

Source

pub const fn was_captured(&self) -> bool

Whether capture was attempted at all.

True for both Absent and Present: the question is whether the caller asked, not what the answer was.

Source

pub const fn present(&self) -> Option<&T>

The captured value, if there is one.

Source

pub const fn as_ref(&self) -> Captured<&T>

Borrow the contents.

Source

pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Captured<U>

Transform a present value, preserving which of the other two states it was otherwise.

Trait Implementations§

Source§

impl<T: Clone> Clone for Captured<T>

Source§

fn clone(&self) -> Captured<T>

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<T: Copy> Copy for Captured<T>

Source§

impl<T: Debug> Debug for Captured<T>

Source§

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

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

impl<T: Eq> Eq for Captured<T>

Source§

impl<T: Hash> Hash for Captured<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq> PartialEq for Captured<T>

Source§

fn eq(&self, other: &Captured<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Captured<T>

Auto Trait Implementations§

§

impl<T> Freeze for Captured<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Captured<T>
where T: RefUnwindSafe,

§

impl<T> Send for Captured<T>
where T: Send,

§

impl<T> Sync for Captured<T>
where T: Sync,

§

impl<T> Unpin for Captured<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Captured<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Captured<T>
where T: UnwindSafe,

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, <T as TryFrom<U>>::Error>

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.