Skip to content

Commit 7ca56e7

Browse files
waywardmonkeyspyfisch
authored andcommitted
Initial no_std support
Since `core::error` isn't in Rust until 1.81, we can't use it and so we only derive `Error` for the error types when building with the `std` feature. Also, `webdriver` implies `std` as well (for now?).
1 parent 56cb5bc commit 7ca56e7

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ edition = "2021"
1111
rust-version = "1.61"
1212

1313
[features]
14-
default = []
14+
default = ["std"]
1515
serde = ["dep:serde", "bitflags/serde"]
16-
webdriver = ["dep:unicode-segmentation"]
16+
std = ["serde?/std"]
17+
webdriver = ["dep:unicode-segmentation", "std"]
1718

1819
[dependencies]
1920
bitflags = "2"
20-
serde = { version = "1.0.0", optional = true, features = ["derive"] }
21+
serde = { version = "1.0.0", optional = true, default-features = false, features = ["derive"] }
2122
unicode-segmentation = { version = "1.2.0", optional = true }
2223

2324
[package.metadata.docs.rs]

convert.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ def convert_key(text, file):
9898
#![allow(clippy::doc_markdown)]
9999
#![allow(deprecated)]
100100
101-
use std::fmt::{self, Display};
102-
use std::str::FromStr;
101+
use core::fmt::{self, Display};
102+
use core::str::FromStr;
103+
#[cfg(feature = "std")]
103104
use std::error::Error;
104105
105106
/// Key represents the meaning of a keypress.
@@ -160,6 +161,7 @@ def convert_key(text, file):
160161
}
161162
}
162163
164+
#[cfg(feature = "std")]
163165
impl Error for UnrecognizedNamedKeyError {}""", file=file)
164166

165167

@@ -170,8 +172,9 @@ def convert_code(text, file):
170172
#![allow(clippy::doc_markdown)]
171173
#![allow(deprecated)]
172174
173-
use std::fmt::{self, Display};
174-
use std::str::FromStr;
175+
use core::fmt::{self, Display};
176+
use core::str::FromStr;
177+
#[cfg(feature = "std")]
175178
use std::error::Error;
176179
177180
/// Code is the physical position of a key.
@@ -278,6 +281,7 @@ def convert_code(text, file):
278281
}
279282
}
280283
284+
#[cfg(feature = "std")]
281285
impl Error for UnrecognizedCodeError {}""", file=file)
282286

283287

src/code.rs

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

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

1112
/// Code is the physical position of a key.
@@ -936,4 +937,5 @@ impl fmt::Display for UnrecognizedCodeError {
936937
}
937938
}
938939

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

src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
77
#![warn(clippy::doc_markdown)]
88
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
9+
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
910

11+
extern crate alloc;
12+
13+
use alloc::string::{String, ToString};
1014
use core::fmt;
1115
use core::str::FromStr;
1216

src/named_key.rs

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

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

1112
/// Key represents the meaning of a keypress.
@@ -1312,4 +1313,5 @@ impl fmt::Display for UnrecognizedNamedKeyError {
13121313
}
13131314
}
13141315

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

0 commit comments

Comments
 (0)