Skip to main content

ConsumingRequest

Trait ConsumingRequest 

Source
pub trait ConsumingRequest {
    type Output;
    type Error;

    // Required method
    fn perform(self) -> Result<Self::Output, Self::Error>;
}
Expand description

A request that is consumed by performing it.

Implemented by crate::close::CloseRequest, where performing twice would mean closing a handle twice. The trait carries that property rather than leaving it to a comment.

§Example

use windows_namespace_request_sys::outcome::Outcome;
use windows_namespace_request_sys::request::ConsumingRequest;
use windows_namespace_request_sys::Win32Error;

// A consumer's cleanup step, written against the trait.
fn perform_all<R: ConsumingRequest>(requests: Vec<R>) -> usize {
    requests
        .into_iter()
        .filter(|_| true)
        .map(ConsumingRequest::perform)
        .filter(Result::is_ok)
        .count()
}

struct FakeClose;

impl ConsumingRequest for FakeClose {
    type Error = Win32Error;
    type Output = ();

    fn perform(self) -> Outcome<()> {
        Ok(())
    }
}

assert_eq!(perform_all(vec![FakeClose, FakeClose]), 2);

Required Associated Types§

Source

type Output

What performing the request produces.

Source

type Error

How performing it can fail.

Required Methods§

Source

fn perform(self) -> Result<Self::Output, Self::Error>

Performs the request on the calling thread, consuming it.

§Errors

Returns the raw Win32 code, unaltered.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§