pub struct Handle { /* private fields */ }
Expand description

This abstracts away some WinAPI calls to set and get some console handles.

It wraps WinAPI’s HANDLE type.

Implementations§

source§

impl Handle

source

pub fn new(handle: HandleType) -> Result<Handle>

Create a new handle of a certaint type.

Examples found in repository?
examples/handle.rs (line 11)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() -> Result<()> {
    // see the description of the types to see what they do.
    let out_put_handle = Handle::new(HandleType::OutputHandle)?;
    let out_put_handle = Handle::new(HandleType::InputHandle)?;
    let curr_out_put_handle = Handle::new(HandleType::CurrentOutputHandle)?;
    let curr_out_put_handle = Handle::new(HandleType::CurrentInputHandle)?;

    // now you have this handle you might want to get the WinAPI `HANDLE` it is wrapping.
    // you can do this by defencing.

    let handle /*:HANDLE*/ = *out_put_handle;

    // you can also pass you own `HANDLE` to create an instance of `Handle`
    let handle = unsafe { Handle::from_raw(handle) }; /* winapi::um::winnt::HANDLE */

    Ok(())
}
source

pub unsafe fn from_raw(handle: HANDLE) -> Self

Construct a handle from a raw handle.

Safety

This is unsafe since there is not guarantee that the underlying HANDLE is thread-safe to implement Send and Sync. Most HANDLE’s however, are thread safe.

Examples found in repository?
examples/handle.rs (line 22)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() -> Result<()> {
    // see the description of the types to see what they do.
    let out_put_handle = Handle::new(HandleType::OutputHandle)?;
    let out_put_handle = Handle::new(HandleType::InputHandle)?;
    let curr_out_put_handle = Handle::new(HandleType::CurrentOutputHandle)?;
    let curr_out_put_handle = Handle::new(HandleType::CurrentInputHandle)?;

    // now you have this handle you might want to get the WinAPI `HANDLE` it is wrapping.
    // you can do this by defencing.

    let handle /*:HANDLE*/ = *out_put_handle;

    // you can also pass you own `HANDLE` to create an instance of `Handle`
    let handle = unsafe { Handle::from_raw(handle) }; /* winapi::um::winnt::HANDLE */

    Ok(())
}
source

pub fn current_out_handle() -> Result<Handle>

Get the handle of the active screen buffer. When using multiple screen buffers this will always point to the to the current screen output buffer.

This function uses CONOUT$ to create a file handle to the current output buffer.

This wraps CreateFileW.

source

pub fn current_in_handle() -> Result<Handle>

Get the handle of the console input buffer.

This function uses CONIN$ to create a file handle to the current input buffer.

This wraps CreateFileW.

source

pub fn output_handle() -> Result<Handle>

Get the handle of the standard output.

On success this function returns the HANDLE to STD_OUTPUT_HANDLE.

This wraps GetStdHandle called with STD_OUTPUT_HANDLE.

source

pub fn input_handle() -> Result<Handle>

Get the handle of the input screen buffer.

On success this function returns the HANDLE to STD_INPUT_HANDLE.

This wraps GetStdHandle called with STD_INPUT_HANDLE.

source

pub fn is_valid_handle(handle: &HANDLE) -> bool

Checks if the console handle is an invalid handle value.

This is done by checking if the passed HANDLE is equal to INVALID_HANDLE_VALUE.

Trait Implementations§

source§

impl Clone for Handle

source§

fn clone(&self) -> Handle

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Handle

source§

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

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

impl Deref for Handle

§

type Target = *mut c_void

The resulting type after dereferencing.
source§

fn deref(&self) -> &HANDLE

Dereferences the value.
source§

impl From<Handle> for Console

source§

fn from(handle: Handle) -> Self

Create a Console instance who’s functions will be executed on the the given Handle

source§

impl From<Handle> for ConsoleMode

source§

fn from(handle: Handle) -> Self

Converts to this type from the input type.
source§

impl From<Handle> for ScreenBuffer

source§

fn from(handle: Handle) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

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

§

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.