libuv_sys2/lib.rs
1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
5
6/// This macro simplifies casting a reference or raw pointer to a uv_SOMETHING_t as a raw pointer
7/// to a uv_SOMETHING_ELSE_t. This is frequently necessary to cast a uv_SOMETHING_t to a
8/// uv_handle_t, but may also be used in other situations (casting a &mut uv_tty_t to a *mut
9/// uv_stream_t, for example). Really, this macro can be used to cast any reference or raw pointer
10/// to a raw pointer of a different type.
11///
12/// # Example
13///
14/// ```
15/// # #[macro_use] extern crate libuv_sys2;
16/// #
17/// # use libuv_sys2::{uv_handle_t, uv_tty_t};
18/// # use std::mem;
19/// #
20/// # fn main() {
21/// #
22/// let mut tty: uv_tty_t = unsafe { mem::zeroed() };
23///
24/// // without the macro, you'd need to cast the reference to a raw pointer of the
25/// // same type, and then cast that as a raw pointer of the target type:
26/// let handle: *mut uv_handle_t = &mut tty as *mut uv_tty_t as *mut uv_handle_t;
27///
28/// // the macro is much more wieldy:
29/// let handle: *mut uv_handle_t = uv_handle!(&mut tty);
30/// #
31/// # }
32/// ```
33#[macro_export]
34macro_rules! uv_handle {
35 (&mut $a:expr) => {
36 &mut $a as *mut _ as *mut _
37 };
38 (&$a:expr) => {
39 &$a as *const _ as *const _
40 };
41 ($a:expr) => {
42 $a as _
43 };
44}