Skip to content

Commit 9f179f6

Browse files
author
Jay Jackson
committed
make everything const
1 parent cb28634 commit 9f179f6

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ output directly).
66

77
## Supports:
88

9-
* Scancode Set 1 and 2
10-
* Dvorak 104-key layout
11-
* US 104-key layout
12-
* UK 105-key layout
13-
* JIS 109-key layout
14-
* Azerty full layout
9+
- Scancode Set 1 and 2
10+
- Dvorak 104-key layout
11+
- US 104-key layout
12+
- UK 105-key layout
13+
- JIS 109-key layout
14+
- Azerty full layout
1515

1616
## Usage
1717

@@ -40,15 +40,15 @@ fn main() {
4040

4141
## Minimum Supported Rust Version (MSRV)
4242

43-
This crate is guaranteed to compile on stable Rust 1.40 and up. It might compile with older versions but that may change in any new patch release.
43+
This crate is guaranteed to compile on stable Rust 1.61 and up. It might compile with older versions but that may change in any new patch release.
4444

4545
## License
4646

4747
Licensed under either of
4848

49-
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
50-
http://www.apache.org/licenses/LICENSE-2.0)
51-
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
49+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
50+
http://www.apache.org/licenses/LICENSE-2.0)
51+
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
5252

5353
at your option.
5454

@@ -61,8 +61,8 @@ any additional terms or conditions.
6161
## Code of Conduct
6262

6363
Contribution to this crate is organized under the terms of the [Rust Code of
64-
Conduct][CoC], the maintainer of this crate, the [Rust Embedded Community][team], promises
64+
Conduct][coc], the maintainer of this crate, the [Rust Embedded Community][team], promises
6565
to intervene to uphold that code of conduct.
6666

67-
[CoC]: https://www.rust-lang.org/policies/code-of-conduct
67+
[coc]: https://www.rust-lang.org/policies/code-of-conduct
6868
[team]: https://github.com/orgs/rust-embedded-community/teams/all

src/lib.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@
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))]
2021
use 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

527525
impl 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

539537
impl 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

Comments
 (0)