1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! lol-macros
mod const_uuid;
mod construct;
mod consts;
mod util;

/// Generate a UUID at compile time.  
///
/// A UUID is something like this: 67e55044-10b1-426f-9247-bb680e5fe0c8
///
/// It is nice to be able to create them at compile time so to use as static
/// random values. These UUID's can be used for generating Windows Pipes, or
/// events or messages (etc) in a way to not collide with other System
/// resources.
#[proc_macro]
pub fn const_uuid(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
    const_uuid::make_expanded(item).map_or_else(
        |e| proc_macro::TokenStream::from(e.to_compile_error()),
        proc_macro::TokenStream::from,
    )
}

/// Generate a UUID at compile time encoded with windows_sys::w! suitable for
/// usage with Windows system calls
#[proc_macro]
pub fn const_uuid_wide(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
    const_uuid::make_expanded_wide(item).map_or_else(
        |e| proc_macro::TokenStream::from(e.to_compile_error()),
        proc_macro::TokenStream::from,
    )
}

/// Generate an Enum like Tuple Struct
#[proc_macro]
pub fn consts(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
    consts::make_expanded(item).map_or_else(
        |e| proc_macro::TokenStream::from(e.to_compile_error()),
        proc_macro::TokenStream::from,
    )
}

/// Derive NativeBitFlag
#[proc_macro_derive(NativeBitFlags, attributes(lol))]
pub fn derive_native_bit_flags(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    consts::derive_native_bit_flag(input).map_or_else(
        |e| proc_macro::TokenStream::from(e.to_compile_error()),
        proc_macro::TokenStream::from,
    )
}

/// We want to make helpers for constructing base types in windows_sys crate
/// so that they dont have to initialize internal fields etc
#[proc_macro]
pub fn construct(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
    construct::make_expanded(item).map_or_else(
        |e| proc_macro::TokenStream::from(e.to_compile_error()),
        proc_macro::TokenStream::from,
    )
}

/// Similar to std::mem::zeroed, except we only support types that are "allowed"
/// to be "zeroed", and therefore we make it "safe", as opposed to
/// std::mem::zeroed (which is unsafe).
///
/// This is pretty useful because lots of things in windows_sys is "unsafe" but
/// in C land it is pretty normal to initialize them with {0}.
#[proc_macro]
pub fn zeroed(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
    construct::make_expand_zeroed(item).map_or_else(
        |e| proc_macro::TokenStream::from(e.to_compile_error()),
        proc_macro::TokenStream::from,
    )
}