rust-embedded-community / pc-keyboard

PS/2 Keyboard Decoder in Rust
Apache License 2.0
96 stars 28 forks source link

Make everything const #16

Closed TheBotlyNoob closed 1 year ago

TheBotlyNoob commented 1 year ago

similar to #15, but it makes more things const.

thejpster commented 1 year ago

I don't think we need to take _layout: T, _set: S as args - they can be specified using a turbofish.

thejpster commented 1 year ago

I merged a PR that adds Github Actions support (I don't think Travis CI works any more for free projects) so could you rebase on that?

thejpster commented 1 year ago

I also had a play with the turbofish idea:

  16   │ --- a/src/lib.rs
  17   │ +++ b/src/lib.rs
  18   │ @@ -314,7 +314,7 @@ where
  19   │      S: ScancodeSet,
  20   │  {
  21   │      /// Make a new Keyboard object with the given layout.
  22   │ -    pub fn new(_layout: T, _set: S, handle_ctrl: HandleControl) -> Keyboard<T, S> {
  23   │ +    pub const fn new(handle_ctrl: HandleControl) -> Keyboard<T, S> {
  24   │          Keyboard {
  25   │              register: 0,
  26   │              num_bits: 0,
  27   │ @@ -564,9 +564,7 @@ mod test {
  28   │  
  29   │      #[test]
  30   │      fn test_f9() {
  31   │ -        let mut k = Keyboard::new(
  32   │ -            layouts::Us104Key,
  33   │ -            ScancodeSet2,
  34   │ +        let mut k: Keyboard<layouts::Us104Key, ScancodeSet2> = Keyboard::new(
  35   │              HandleControl::MapLettersToUnicode,
  36   │          );
  37   │          // start
TheBotlyNoob commented 1 year ago

whoops.

TheBotlyNoob commented 1 year ago

could you reopen the pr?

thejpster commented 1 year ago

No it won't let me. This might be because you closed it. Open another?

Also - pro tip: don't work on the main branch in your fork otherwise your fork will always have commits upstream does not. Instead, always do the work in a branch and open a PR from there. This will also make rebasing easier.

TheBotlyNoob commented 1 year ago

Okay, thanks for the tip. I'm not very experienced at git.