Skip to content

Commit c71eca0

Browse files
committed
update format and fix warning
1 parent 473463a commit c71eca0

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

src/convert/_build.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ pub struct ConvertImport1Template {
176176
177177
178178
pub fn {{ty|lower}}_to_{{code_ty|lower}}(value: &{{ty}}) -> {{code_ty}} {
179-
{% if const_check -%}
179+
{%- if const_check %}
180180
#[allow(unused_parens)]
181181
const {
182-
{% for entry in entries -%}
182+
{%- for entry in entries %}
183183
assert!({{to_code_expr.0}}(&{{"{" ~ value_prefix}}{{ entry.0 | pad_right(*k_len) }}{{value_suffix ~ "}"}}){{to_code_expr.1}} == {{entry.1 | hex}});
184-
{% endfor -%}
184+
{%- endfor %}
185185
}
186-
{% endif -%}
186+
{%- endif %}
187187
{{to_code_expr.0}}value{{to_code_expr.1}}
188188
}
189189
@@ -192,28 +192,29 @@ impl crate::numeric::AsCode<{{ty}}> for crate::numeric::Coder {
192192
fn as_code(value: &{{ty}}) -> Self::Code {
193193
{{ty|lower}}_to_{{code_ty|lower}}(value)
194194
}
195+
#[allow(unreachable_patterns)]
195196
fn from_code(code: Self::Code) -> Option<{{ty}}> {
196197
match code {
197-
{% for entry in entries|unique -%}
198+
{%- for entry in entries|unique %}
198199
{{entry.1 | hex}} => Some({{value_prefix}}{{ entry.0 | pad_right(*k_len) }}{{value_suffix}}),
199-
{% endfor -%}
200+
{%- endfor %}
200201
_ => None,
201202
}
202203
}
203-
{% if let Some(from_code_expr) = from_code_expr -%}
204+
{%- if let Some(from_code_expr) = from_code_expr %}
204205
unsafe fn from_code_unchecked(code: Self::Code) -> {{ty}} {
205206
{{from_code_expr.0}}code{{from_code_expr.1}}
206207
}
207-
{% endif -%}
208+
{%- endif %}
208209
}
209210
210211
{% if !const_check -%}
211212
#[test]
212213
#[allow(unused_parens)]
213214
fn test_code() {
214-
{% for entry in entries -%}
215+
{%- for entry in entries %}
215216
assert!({{to_code_expr.0}}(&{{"{" ~ value_prefix}}{{ entry.0 | pad_right(*k_len) }}{{value_suffix ~ "}"}}){{to_code_expr.1}} == {{entry.1 | hex}});
216-
{% endfor -%}
217+
{%- endfor %}
217218
}
218219
{% endif -%}
219220
"#)]
@@ -375,7 +376,8 @@ impl KeyType {
375376
pub fn as_from_code_expr(self) -> Option<&'static str> {
376377
match self {
377378
KeyType::HUT => None,
378-
KeyType::Winput | KeyType::WinVk => Some("unsafe { crate::numeric::convert_from_code_unchecked({}) }"),
379+
KeyType::Winput => Some("unsafe { std::mem::transmute({}) }"),
380+
KeyType::WinVk => Some("Vk({})"),
379381
_ => None,
380382
}
381383
}

src/numeric/generated.HUT.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ impl crate::numeric::AsCode<Usage> for crate::numeric::Coder {
1010
fn as_code(value: &Usage) -> Self::Code {
1111
usage_to_u32(value)
1212
}
13+
#[allow(unreachable_patterns)]
1314
fn from_code(code: Self::Code) -> Option<Usage> {
1415
match code {
1516
0x90001 => Some(Button::Button(1) .usage()),
@@ -158,7 +159,7 @@ impl crate::numeric::AsCode<Usage> for crate::numeric::Coder {
158159
_ => None,
159160
}
160161
}
161-
}
162+
}
162163

163164
#[test]
164165
#[allow(unused_parens)]
@@ -307,4 +308,4 @@ fn test_code() {
307308
assert!(AsUsage::usage_value((&{KeyboardKeypad::KeypadPeriodandDelete .usage()})) == 0x70063);
308309
assert!(AsUsage::usage_value((&{KeyboardKeypad::KeypadPlus .usage()})) == 0x70057);
309310
assert!(AsUsage::usage_value((&{KeyboardKeypad::KeypadStar .usage()})) == 0x70055);
310-
}
311+
}

src/numeric/generated.WinVk.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub fn vk_to_u16(value: &Vk) -> u16 {
256256
assert!((&{keys::VK_SEPARATOR }).0 == 0x6C);
257257
assert!((&{keys::VK_LAUNCH_APP1 }).0 == 0xB6);
258258
assert!((&{keys::VK_LAUNCH_APP2 }).0 == 0xB7);
259-
}
259+
}
260260
value.0
261261
}
262262

@@ -265,6 +265,7 @@ impl crate::numeric::AsCode<Vk> for crate::numeric::Coder {
265265
fn as_code(value: &Vk) -> Self::Code {
266266
vk_to_u16(value)
267267
}
268+
#[allow(unreachable_patterns)]
268269
fn from_code(code: Self::Code) -> Option<Vk> {
269270
match code {
270271
0x01 => Some(keys::VK_LBUTTON ),
@@ -518,7 +519,7 @@ impl crate::numeric::AsCode<Vk> for crate::numeric::Coder {
518519
}
519520
}
520521
unsafe fn from_code_unchecked(code: Self::Code) -> Vk {
521-
unsafe { crate::numeric::convert_from_code_unchecked(code) }
522-
}
522+
Vk(code)
523523
}
524+
}
524525

src/numeric/generated.Winput.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub fn vk_to_u8(value: &Vk) -> u8 {
164164
assert!(*(&{Vk::Separator }) as u8 == 0x6C);
165165
assert!(*(&{Vk::StartApp1 }) as u8 == 0xB6);
166166
assert!(*(&{Vk::StartApp2 }) as u8 == 0xB7);
167-
}
167+
}
168168
*value as u8
169169
}
170170

@@ -173,6 +173,7 @@ impl crate::numeric::AsCode<Vk> for crate::numeric::Coder {
173173
fn as_code(value: &Vk) -> Self::Code {
174174
vk_to_u8(value)
175175
}
176+
#[allow(unreachable_patterns)]
176177
fn from_code(code: Self::Code) -> Option<Vk> {
177178
match code {
178179
0x01 => Some(Vk::MouseLeft ),
@@ -339,7 +340,7 @@ impl crate::numeric::AsCode<Vk> for crate::numeric::Coder {
339340
}
340341
}
341342
unsafe fn from_code_unchecked(code: Self::Code) -> Vk {
342-
unsafe { crate::numeric::convert_from_code_unchecked(code) }
343-
}
343+
unsafe { std::mem::transmute(code) }
344344
}
345+
}
345346

src/numeric/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub trait AsCode<T> {
1313
}
1414
}
1515

16+
#[allow(dead_code)]
1617
unsafe fn convert_from_code_unchecked<T, C>(code: C) -> T
1718
where
1819
Coder: AsCode<T, Code = C>,

0 commit comments

Comments
 (0)