Skip to content

Initial no_std support #69

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

Merged
merged 1 commit into from
Apr 21, 2025
Merged
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
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ edition = "2021"
rust-version = "1.61"

[features]
default = []
default = ["std"]
serde = ["dep:serde", "bitflags/serde"]
webdriver = ["dep:unicode-segmentation"]
std = ["serde?/std"]
webdriver = ["dep:unicode-segmentation", "std"]

[dependencies]
bitflags = "2"
serde = { version = "1.0.0", optional = true, features = ["derive"] }
serde = { version = "1.0.0", optional = true, default-features = false, features = ["derive"] }
unicode-segmentation = { version = "1.2.0", optional = true }

[package.metadata.docs.rs]
Expand Down
12 changes: 8 additions & 4 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ def convert_key(text, file):
#![allow(clippy::doc_markdown)]
#![allow(deprecated)]

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

/// Key represents the meaning of a keypress.
Expand Down Expand Up @@ -158,6 +159,7 @@ def convert_key(text, file):
}
}

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


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

use std::fmt::{self, Display};
use std::str::FromStr;
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 Down Expand Up @@ -274,6 +277,7 @@ def convert_code(text, file):
}
}

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


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

use std::fmt::{self, Display};
use std::str::FromStr;
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 Down Expand Up @@ -934,4 +935,5 @@ impl fmt::Display for UnrecognizedCodeError {
}
}

#[cfg(feature = "std")]
impl Error for UnrecognizedCodeError {}
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

#![warn(clippy::doc_markdown)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]

extern crate alloc;

use alloc::string::{String, ToString};
use core::fmt;
use core::str::FromStr;

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

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

/// Key represents the meaning of a keypress.
Expand Down Expand Up @@ -1311,4 +1312,5 @@ impl fmt::Display for UnrecognizedNamedKeyError {
}
}

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