Skip to content

Commit bac5be4

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 allows the `no_std` support to be slightly better by allowing `core::error::Error` to be impl'd for the error types.
1 parent 7ca56e7 commit bac5be4

File tree

7 files changed

+18
-44
lines changed

7 files changed

+18
-44
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 = ["std"]

convert.py

+6-8
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

@@ -98,16 +100,15 @@ def convert_key(text, file):
98100
#![allow(clippy::doc_markdown)]
99101
#![allow(deprecated)]
100102
103+
use core::error::Error;
101104
use core::fmt::{self, Display};
102105
use core::str::FromStr;
103-
#[cfg(feature = "std")]
104-
use std::error::Error;
105106
106107
/// Key represents the meaning of a keypress.
107108
///
108109
/// Specification:
109110
/// <https://w3c.github.io/uievents-key/>
110-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
111+
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, PartialOrd, Ord)]
111112
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
112113
#[non_exhaustive]
113114
pub enum NamedKey {""", file=file)
@@ -161,7 +162,6 @@ def convert_key(text, file):
161162
}
162163
}
163164
164-
#[cfg(feature = "std")]
165165
impl Error for UnrecognizedNamedKeyError {}""", file=file)
166166

167167

@@ -172,10 +172,9 @@ def convert_code(text, file):
172172
#![allow(clippy::doc_markdown)]
173173
#![allow(deprecated)]
174174
175+
use core::error::Error;
175176
use core::fmt::{self, Display};
176177
use core::str::FromStr;
177-
#[cfg(feature = "std")]
178-
use std::error::Error;
179178
180179
/// Code is the physical position of a key.
181180
///
@@ -185,7 +184,7 @@ def convert_code(text, file):
185184
///
186185
/// Specification:
187186
/// <https://w3c.github.io/uievents-code/>
188-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
187+
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, PartialOrd, Ord)]
189188
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
190189
#[non_exhaustive]
191190
pub enum Code {""", file=file)
@@ -281,7 +280,6 @@ def convert_code(text, file):
281280
}
282281
}
283282
284-
#[cfg(feature = "std")]
285283
impl Error for UnrecognizedCodeError {}""", file=file)
286284

287285

src/code.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
#![allow(clippy::doc_markdown)]
55
#![allow(deprecated)]
66

7+
use core::error::Error;
78
use core::fmt::{self, Display};
89
use core::str::FromStr;
9-
#[cfg(feature = "std")]
10-
use std::error::Error;
1110

1211
/// Code is the physical position of a key.
1312
///
@@ -17,7 +16,7 @@ use std::error::Error;
1716
///
1817
/// Specification:
1918
/// <https://w3c.github.io/uievents-code/>
20-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
19+
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, PartialOrd, Ord)]
2120
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2221
#[non_exhaustive]
2322
pub enum Code {
@@ -358,6 +357,7 @@ pub enum Code {
358357
Katakana,
359358
/// This value code should be used when no other
360359
/// value given in this specification is appropriate.
360+
#[default]
361361
Unidentified,
362362
/// <kbd>F1</kbd>
363363
F1,
@@ -937,5 +937,4 @@ impl fmt::Display for UnrecognizedCodeError {
937937
}
938938
}
939939

940-
#[cfg(feature = "std")]
941940
impl Error for UnrecognizedCodeError {}

src/lib.rs

+2-25
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub mod webdriver;
3232
use serde::{Deserialize, Serialize};
3333

3434
/// Describes the state a key is in.
35-
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
35+
#[derive(Copy, Clone, Debug, Default, Eq, Hash, PartialEq, PartialOrd, Ord)]
3636
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3737
pub enum KeyState {
3838
/// The key is pressed down.
@@ -41,6 +41,7 @@ pub enum KeyState {
4141
///
4242
/// [keydown]: https://w3c.github.io/uievents/#event-type-keydown
4343
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Element/keydown_event
44+
#[default]
4445
Down,
4546
/// The key is not pressed / was just released.
4647
///
@@ -260,36 +261,12 @@ impl Key {
260261
}
261262
}
262263

263-
impl Default for KeyState {
264-
fn default() -> KeyState {
265-
KeyState::Down
266-
}
267-
}
268-
269264
impl Default for Key {
270265
fn default() -> Self {
271266
Self::Named(NamedKey::default())
272267
}
273268
}
274269

275-
impl Default for NamedKey {
276-
fn default() -> Self {
277-
Self::Unidentified
278-
}
279-
}
280-
281-
impl Default for Code {
282-
fn default() -> Code {
283-
Code::Unidentified
284-
}
285-
}
286-
287-
impl Default for Location {
288-
fn default() -> Location {
289-
Location::Standard
290-
}
291-
}
292-
293270
/// Return the first codepoint of a string.
294271
///
295272
/// # 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

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
#![allow(clippy::doc_markdown)]
55
#![allow(deprecated)]
66

7+
use core::error::Error;
78
use core::fmt::{self, Display};
89
use core::str::FromStr;
9-
#[cfg(feature = "std")]
10-
use std::error::Error;
1110

1211
/// Key represents the meaning of a keypress.
1312
///
1413
/// Specification:
1514
/// <https://w3c.github.io/uievents-key/>
16-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
15+
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, PartialOrd, Ord)]
1716
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1817
#[non_exhaustive]
1918
pub enum NamedKey {
2019
/// This key value is used when an implementation is unable to
2120
/// identify another key value, due to either hardware,
2221
/// platform, or software constraints.
22+
#[default]
2323
Unidentified,
2424
/// 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.
2525
Alt,
@@ -1313,5 +1313,4 @@ impl fmt::Display for UnrecognizedNamedKeyError {
13131313
}
13141314
}
13151315

1316-
#[cfg(feature = "std")]
13171316
impl Error for UnrecognizedNamedKeyError {}

0 commit comments

Comments
 (0)