Skip to content

Update MSRV to 1.81 #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
matrix:
toolchain:
- stable
- "1.61"
- "1.81"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/pyfisch/keyboard-types"
keywords = ["keyboard", "input", "event", "webdriver"]
edition = "2021"
rust-version = "1.61"
rust-version = "1.81"

[features]
default = ["std"]
Expand Down
14 changes: 6 additions & 8 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def emit_enum_entries(display, file):
print(f" /// {line}", file=file)
if deprecated:
print(" #[deprecated = \"marked as legacy in the spec, use Meta instead\"]", file=file)
if key == "Unidentified":
print(" #[default]", file=file)
print(f" {key},", file=file)


Expand Down Expand Up @@ -98,16 +100,15 @@ def convert_key(text, file):
#![allow(clippy::doc_markdown)]
#![allow(deprecated)]

use core::error::Error;
use core::fmt::{self, Display};
use core::str::FromStr;
#[cfg(feature = "std")]
use std::error::Error;

/// Key represents the meaning of a keypress.
///
/// Specification:
/// <https://w3c.github.io/uievents-key/>
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum NamedKey {""", file=file)
Expand Down Expand Up @@ -161,7 +162,6 @@ def convert_key(text, file):
}
}

#[cfg(feature = "std")]
impl Error for UnrecognizedNamedKeyError {}""", file=file)


Expand All @@ -172,10 +172,9 @@ def convert_code(text, file):
#![allow(clippy::doc_markdown)]
#![allow(deprecated)]

use core::error::Error;
use core::fmt::{self, Display};
use core::str::FromStr;
#[cfg(feature = "std")]
use std::error::Error;

/// Code is the physical position of a key.
///
Expand All @@ -185,7 +184,7 @@ def convert_code(text, file):
///
/// Specification:
/// <https://w3c.github.io/uievents-code/>
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum Code {""", file=file)
Expand Down Expand Up @@ -281,7 +280,6 @@ def convert_code(text, file):
}
}

#[cfg(feature = "std")]
impl Error for UnrecognizedCodeError {}""", file=file)


Expand Down
7 changes: 3 additions & 4 deletions src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#![allow(clippy::doc_markdown)]
#![allow(deprecated)]

use core::error::Error;
use core::fmt::{self, Display};
use core::str::FromStr;
#[cfg(feature = "std")]
use std::error::Error;

/// Code is the physical position of a key.
///
Expand All @@ -17,7 +16,7 @@ use std::error::Error;
///
/// Specification:
/// <https://w3c.github.io/uievents-code/>
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum Code {
Expand Down Expand Up @@ -358,6 +357,7 @@ pub enum Code {
Katakana,
/// This value code should be used when no other
/// value given in this specification is appropriate.
#[default]
Unidentified,
/// <kbd>F1</kbd>
F1,
Expand Down Expand Up @@ -937,5 +937,4 @@ impl fmt::Display for UnrecognizedCodeError {
}
}

#[cfg(feature = "std")]
impl Error for UnrecognizedCodeError {}
27 changes: 2 additions & 25 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub mod webdriver;
use serde::{Deserialize, Serialize};

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

impl Default for KeyState {
fn default() -> KeyState {
KeyState::Down
}
}

impl Default for Key {
fn default() -> Self {
Self::Named(NamedKey::default())
}
}

impl Default for NamedKey {
fn default() -> Self {
Self::Unidentified
}
}

impl Default for Code {
fn default() -> Code {
Code::Unidentified
}
}

impl Default for Location {
fn default() -> Location {
Location::Standard
}
}

/// Return the first codepoint of a string.
///
/// # Panics
Expand Down
3 changes: 2 additions & 1 deletion src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// number keys can be above the letters or on the numpad. This enum allows differentiating them.
///
/// See also [MDN's documentation](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/location).
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Location {
/// The key is in its "normal" location on the keyboard.
Expand All @@ -31,6 +31,7 @@ pub enum Location {
env!("CARGO_PKG_VERSION"),
"/source/docs/ATTRIBUTION.md",
)]
#[default]
Standard = 0x00,

/// The key activated originated from the left key location (when there
Expand Down
7 changes: 3 additions & 4 deletions src/named_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
#![allow(clippy::doc_markdown)]
#![allow(deprecated)]

use core::error::Error;
use core::fmt::{self, Display};
use core::str::FromStr;
#[cfg(feature = "std")]
use std::error::Error;

/// Key represents the meaning of a keypress.
///
/// Specification:
/// <https://w3c.github.io/uievents-key/>
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum NamedKey {
/// This key value is used when an implementation is unable to
/// identify another key value, due to either hardware,
/// platform, or software constraints.
#[default]
Unidentified,
/// 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.
Alt,
Expand Down Expand Up @@ -1313,5 +1313,4 @@ impl fmt::Display for UnrecognizedNamedKeyError {
}
}

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