99//! that the interrupt can access, which is unsafe.
1010
1111#![ cfg_attr( not( test) , no_std) ]
12+ #[ cfg( test) ]
13+ extern crate std as core;
1214
1315// ****************************************************************************
1416//
1517// Imports
1618//
1719// ****************************************************************************
1820
19- #[ cfg( not( test) ) ]
2021use core:: marker:: PhantomData ;
2122
22- #[ cfg( test) ]
23- use std:: marker:: PhantomData ;
24-
2523// ****************************************************************************
2624//
2725// Modules
@@ -314,7 +312,7 @@ where
314312 S : ScancodeSet ,
315313{
316314 /// 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 > {
318316 Keyboard {
319317 register : 0 ,
320318 num_bits : 0 ,
@@ -340,7 +338,7 @@ where
340338 }
341339
342340 /// Get the current Ctrl key mapping.
343- pub fn get_ctrl_handling ( & self ) -> HandleControl {
341+ pub const fn get_ctrl_handling ( & self ) -> HandleControl {
344342 self . handle_ctrl
345343 }
346344
@@ -490,16 +488,16 @@ where
490488 }
491489 }
492490
493- fn get_bit ( word : u16 , offset : usize ) -> bool {
491+ const fn get_bit ( word : u16 , offset : usize ) -> bool {
494492 ( ( word >> offset) & 0x0001 ) != 0
495493 }
496494
497- fn has_even_number_bits ( data : u8 ) -> bool {
495+ const fn has_even_number_bits ( data : u8 ) -> bool {
498496 ( data. count_ones ( ) % 2 ) == 0
499497 }
500498
501499 /// 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 > {
503501 let start_bit = Self :: get_bit ( word, 0 ) ;
504502 let parity_bit = Self :: get_bit ( word, 9 ) ;
505503 let stop_bit = Self :: get_bit ( word, 10 ) ;
@@ -525,7 +523,7 @@ where
525523}
526524
527525impl KeyEvent {
528- pub fn new ( code : KeyCode , state : KeyState ) -> KeyEvent {
526+ pub const fn new ( code : KeyCode , state : KeyState ) -> KeyEvent {
529527 KeyEvent { code, state }
530528 }
531529}
@@ -537,15 +535,15 @@ impl KeyEvent {
537535// ****************************************************************************
538536
539537impl Modifiers {
540- pub fn is_shifted ( & self ) -> bool {
538+ pub const fn is_shifted ( & self ) -> bool {
541539 self . lshift | self . rshift
542540 }
543541
544- pub fn is_ctrl ( & self ) -> bool {
542+ pub const fn is_ctrl ( & self ) -> bool {
545543 self . lctrl | self . rctrl
546544 }
547545
548- pub fn is_caps ( & self ) -> bool {
546+ pub const fn is_caps ( & self ) -> bool {
549547 ( self . lshift | self . rshift ) ^ self . capslock
550548 }
551549}
0 commit comments