9
9
//! that the interrupt can access, which is unsafe.
10
10
11
11
#![ cfg_attr( not( test) , no_std) ]
12
+ #[ cfg( test) ]
13
+ extern crate std as core;
12
14
13
15
// ****************************************************************************
14
16
//
15
17
// Imports
16
18
//
17
19
// ****************************************************************************
18
20
19
- #[ cfg( not( test) ) ]
20
21
use core:: marker:: PhantomData ;
21
22
22
- #[ cfg( test) ]
23
- use std:: marker:: PhantomData ;
24
-
25
23
// ****************************************************************************
26
24
//
27
25
// Modules
@@ -314,7 +312,7 @@ where
314
312
S : ScancodeSet ,
315
313
{
316
314
/// Make a new Keyboard object with the given layout.
317
- pub fn new ( handle_ctrl : HandleControl ) -> Keyboard < T , S > {
315
+ pub const fn new ( handle_ctrl : HandleControl ) -> Keyboard < T , S > {
318
316
Keyboard {
319
317
register : 0 ,
320
318
num_bits : 0 ,
@@ -340,7 +338,7 @@ where
340
338
}
341
339
342
340
/// Get the current Ctrl key mapping.
343
- pub fn get_ctrl_handling ( & self ) -> HandleControl {
341
+ pub const fn get_ctrl_handling ( & self ) -> HandleControl {
344
342
self . handle_ctrl
345
343
}
346
344
@@ -490,16 +488,16 @@ where
490
488
}
491
489
}
492
490
493
- fn get_bit ( word : u16 , offset : usize ) -> bool {
491
+ const fn get_bit ( word : u16 , offset : usize ) -> bool {
494
492
( ( word >> offset) & 0x0001 ) != 0
495
493
}
496
494
497
- fn has_even_number_bits ( data : u8 ) -> bool {
495
+ const fn has_even_number_bits ( data : u8 ) -> bool {
498
496
( data. count_ones ( ) % 2 ) == 0
499
497
}
500
498
501
499
/// Check 11-bit word has 1 start bit, 1 stop bit and an odd parity bit.
502
- fn check_word ( word : u16 ) -> Result < u8 , Error > {
500
+ const fn check_word ( word : u16 ) -> Result < u8 , Error > {
503
501
let start_bit = Self :: get_bit ( word, 0 ) ;
504
502
let parity_bit = Self :: get_bit ( word, 9 ) ;
505
503
let stop_bit = Self :: get_bit ( word, 10 ) ;
@@ -525,7 +523,7 @@ where
525
523
}
526
524
527
525
impl KeyEvent {
528
- pub fn new ( code : KeyCode , state : KeyState ) -> KeyEvent {
526
+ pub const fn new ( code : KeyCode , state : KeyState ) -> KeyEvent {
529
527
KeyEvent { code, state }
530
528
}
531
529
}
@@ -537,15 +535,15 @@ impl KeyEvent {
537
535
// ****************************************************************************
538
536
539
537
impl Modifiers {
540
- pub fn is_shifted ( & self ) -> bool {
538
+ pub const fn is_shifted ( & self ) -> bool {
541
539
self . lshift | self . rshift
542
540
}
543
541
544
- pub fn is_ctrl ( & self ) -> bool {
542
+ pub const fn is_ctrl ( & self ) -> bool {
545
543
self . lctrl | self . rctrl
546
544
}
547
545
548
- pub fn is_caps ( & self ) -> bool {
546
+ pub const fn is_caps ( & self ) -> bool {
549
547
( self . lshift | self . rshift ) ^ self . capslock
550
548
}
551
549
}
0 commit comments