Skip to content

Commit 1a350ec

Browse files
Update MSRV to 1.81
This also changes to use the derived `Default` for enums since that is available with a later MSRV (and would otherwise have clippy warnings). Updating the MSRV will allow the `no_std` support to be slightly better by allowing `core::error::Error` to be impl'd for the error types rather than only having that for `std` builds.
1 parent 7d2258e commit 1a350ec

File tree

7 files changed

+14
-32
lines changed

7 files changed

+14
-32
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
matrix:
1111
toolchain:
1212
- stable
13-
- "1.61"
13+
- "1.81"
1414
steps:
1515
- uses: actions/checkout@v4
1616
- uses: dtolnay/rust-toolchain@master

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
88
repository = "https://github.com/pyfisch/keyboard-types"
99
keywords = ["keyboard", "input", "event", "webdriver"]
1010
edition = "2021"
11-
rust-version = "1.61"
11+
rust-version = "1.81"
1212

1313
[features]
1414
default = []

convert.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def emit_enum_entries(display, file):
5959
print(f" /// {line}", file=file)
6060
if deprecated:
6161
print(" #[deprecated = \"marked as legacy in the spec, use Meta instead\"]", file=file)
62+
if key == "Unidentified":
63+
print(" #[default]", file=file)
6264
print(f" {key},", file=file)
6365

6466

@@ -106,7 +108,7 @@ def convert_key(text, file):
106108
///
107109
/// Specification:
108110
/// <https://w3c.github.io/uievents-key/>
109-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
111+
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, PartialOrd, Ord)]
110112
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
111113
#[non_exhaustive]
112114
pub enum NamedKey {""", file=file)
@@ -180,7 +182,7 @@ def convert_code(text, file):
180182
///
181183
/// Specification:
182184
/// <https://w3c.github.io/uievents-code/>
183-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
185+
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, PartialOrd, Ord)]
184186
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
185187
#[non_exhaustive]
186188
pub enum Code {""", file=file)

src/code.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::error::Error;
1616
///
1717
/// Specification:
1818
/// <https://w3c.github.io/uievents-code/>
19-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
19+
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, PartialOrd, Ord)]
2020
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2121
#[non_exhaustive]
2222
pub enum Code {
@@ -355,6 +355,7 @@ pub enum Code {
355355
Katakana,
356356
/// This value code should be used when no other
357357
/// value given in this specification is appropriate.
358+
#[default]
358359
Unidentified,
359360
/// <kbd>F1</kbd>
360361
F1,

src/lib.rs

+2-25
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub mod webdriver;
2828
use serde::{Deserialize, Serialize};
2929

3030
/// Describes the state a key is in.
31-
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
31+
#[derive(Copy, Clone, Debug, Default, Eq, Hash, PartialEq, PartialOrd, Ord)]
3232
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3333
pub enum KeyState {
3434
/// The key is pressed down.
@@ -37,6 +37,7 @@ pub enum KeyState {
3737
///
3838
/// [keydown]: https://w3c.github.io/uievents/#event-type-keydown
3939
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Element/keydown_event
40+
#[default]
4041
Down,
4142
/// The key is not pressed / was just released.
4243
///
@@ -256,36 +257,12 @@ impl Key {
256257
}
257258
}
258259

259-
impl Default for KeyState {
260-
fn default() -> KeyState {
261-
KeyState::Down
262-
}
263-
}
264-
265260
impl Default for Key {
266261
fn default() -> Self {
267262
Self::Named(NamedKey::default())
268263
}
269264
}
270265

271-
impl Default for NamedKey {
272-
fn default() -> Self {
273-
Self::Unidentified
274-
}
275-
}
276-
277-
impl Default for Code {
278-
fn default() -> Code {
279-
Code::Unidentified
280-
}
281-
}
282-
283-
impl Default for Location {
284-
fn default() -> Location {
285-
Location::Standard
286-
}
287-
}
288-
289266
/// Return the first codepoint of a string.
290267
///
291268
/// # Panics

src/location.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// number keys can be above the letters or on the numpad. This enum allows differentiating them.
66
///
77
/// See also [MDN's documentation](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/location).
8-
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
8+
#[derive(Copy, Clone, Debug, Default, Eq, Hash, PartialEq, PartialOrd, Ord)]
99
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1010
pub enum Location {
1111
/// The key is in its "normal" location on the keyboard.
@@ -31,6 +31,7 @@ pub enum Location {
3131
env!("CARGO_PKG_VERSION"),
3232
"/source/docs/ATTRIBUTION.md",
3333
)]
34+
#[default]
3435
Standard = 0x00,
3536

3637
/// The key activated originated from the left key location (when there

src/named_key.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ use std::error::Error;
1212
///
1313
/// Specification:
1414
/// <https://w3c.github.io/uievents-key/>
15-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
15+
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, PartialOrd, Ord)]
1616
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1717
#[non_exhaustive]
1818
pub enum NamedKey {
1919
/// This key value is used when an implementation is unable to
2020
/// identify another key value, due to either hardware,
2121
/// platform, or software constraints.
22+
#[default]
2223
Unidentified,
2324
/// The <kbd>Alt</kbd> (Alternative) key.<br/> This key enables the alternate modifier function for interpreting concurrent or subsequent keyboard input.<br/> This key value is also used for the Apple <kbd>Option</kbd> key.
2425
Alt,

0 commit comments

Comments
 (0)