]>
git.proxmox.com Git - rustc.git/blob - vendor/windows-bindgen/src/enums.rs
3 pub fn gen(gen
: &Gen
, def
: TypeDef
) -> TokenStream
{
4 let type_name
= gen
.reader
.type_def_type_name(def
);
5 let ident
= to_ident(type_name
.name
);
6 let underlying_type
= gen
.reader
.type_def_underlying_type(def
);
7 let underlying_type
= gen
.type_name(&underlying_type
);
8 let is_scoped
= gen
.reader
.type_def_is_scoped(def
);
9 let cfg
= gen
.reader
.type_def_cfg(def
, &[]);
10 let doc
= gen
.cfg_doc(&cfg
);
11 let features
= gen
.cfg_features(&cfg
);
13 let fields
: Vec
<(TokenStream
, TokenStream
)> = gen
20 .contains(FieldAttributes
::LITERAL
)
22 let field_name
= to_ident(gen
.reader
.field_name(field
));
23 let constant
= gen
.reader
.field_constant(field
).unwrap();
24 let value
= gen
.value(&gen
.reader
.constant_value(constant
));
26 Some((field_name
, value
))
37 // Unfortunately, Rust requires these to be derived to allow constant patterns.
38 #[derive(::core::cmp::PartialEq, ::core::cmp::Eq)]
42 let mut tokens
= if is_scoped
|| !gen
.sys
{
48 pub struct #ident(pub #underlying_type);
54 pub type #ident = #underlying_type;
58 tokens
.combine(&if is_scoped
{
59 let fields
= fields
.iter().map(|(field_name
, value
)| {
61 pub const #field_name: Self = Self(#value);
72 let fields
= fields
.iter().map(|(field_name
, value
)| {
76 pub const #field_name: #ident = #ident(#value);
83 } else if !gen
.standalone
{
84 let fields
= fields
.iter().map(|(field_name
, value
)| {
88 pub const #field_name: #ident = #value;
99 if is_scoped
|| !gen
.sys
{
100 tokens
.combine("e
! {
102 impl ::core
::marker
::Copy
for #ident {}
104 impl ::core
::clone
::Clone
for #ident {
105 fn clone(&self) -> Self {
113 tokens
.combine("e
! {
115 impl ::core
::default::Default
for #ident {
116 fn default() -> Self {
124 let name
= type_name
.name
;
125 tokens
.combine("e
! {
127 impl ::windows
::core
::TypeKind
for #ident {
128 type TypeKind
= ::windows
::core
::CopyType
;
131 impl ::core
::fmt
::Debug
for #ident {
132 fn fmt(&self, f
: &mut ::core
::fmt
::Formatter
<'_
>) -> ::core
::fmt
::Result
{
133 f
.debug_tuple(#name).field(&self.0).finish()
138 if gen
.reader
.type_def_is_flags(def
) {
139 tokens
.combine("e
! {
142 pub const fn contains(&self, other
: Self) -> bool
{
143 self.0 & other
.0 == other
.0
147 impl ::core
::ops
::BitOr
for #ident {
150 fn bitor(self, other
: Self) -> Self {
151 Self(self.0 | other
.0)
155 impl ::core
::ops
::BitAnd
for #ident {
158 fn bitand(self, other
: Self) -> Self {
159 Self(self.0 & other
.0)
163 impl ::core
::ops
::BitOrAssign
for #ident {
164 fn bitor_assign(&mut self, other
: Self) {
165 self.0.bitor_assign(other
.0)
169 impl ::core
::ops
::BitAndAssign
for #ident {
170 fn bitand_assign(&mut self, other
: Self) {
171 self.0.bitand_assign(other
.0)
175 impl ::core
::ops
::Not
for #ident {
178 fn not(self) -> Self {
188 .contains(TypeAttributes
::WINRT
)
191 Literal
::byte_string(gen
.reader
.type_def_signature(def
, &[]).as_bytes());
193 tokens
.combine("e
! {
195 impl ::windows
::core
::RuntimeType
for #ident {
196 const SIGNATURE
: ::windows
::imp
::ConstBuffer
= ::windows
::imp
::ConstBuffer
::from_slice(#signature);