Skip to content

Commit 0f5e1e4

Browse files
committed
pcsc: switch to bitflags 2
bitflags releases a major version, but we use it in the public interface, so upgrading is a breaking change. However, the bitflags changelog provides guidance on how to keep 2 mostly compatible with 1: https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md#200 This is not perfect, there is still some chance of breaking dependents, but I think/hope it is OK. I think it's better than sticking with 1 only or bumping pcsc major. The MSRV is bumped to match bitflags.
1 parent 3d0dd9b commit 0f5e1e4

File tree

6 files changed

+37
-8
lines changed

6 files changed

+37
-8
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
os: [ubuntu-22.04, windows-2022, macos-14]
1414
toolchain: [stable]
1515
include:
16-
- {os: ubuntu-22.04, toolchain: '1.38.0'}
16+
- {os: ubuntu-22.04, toolchain: '1.56.0'}
1717
- {os: ubuntu-22.04, toolchain: beta}
1818
- {os: ubuntu-22.04, toolchain: nightly}
1919

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[workspace]
22
members = ["pcsc", "pcsc-sys"]
3+
resolver = "2"

pcsc-sys/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ homepage = "https://github.com/bluetech/pcsc-rust"
1111
authors = ["Ran Benita <[email protected]>"]
1212
build = "build.rs"
1313
links = "pcsc"
14-
rust-version = "1.38"
15-
edition = "2018"
14+
rust-version = "1.56"
15+
edition = "2021"
1616

1717
[build-dependencies]
1818
pkg-config = "0.3.9"

pcsc/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ repository = "https://github.com/bluetech/pcsc-rust"
1010
homepage = "https://github.com/bluetech/pcsc-rust"
1111
readme = "../README.md"
1212
authors = ["Ran Benita <[email protected]>"]
13-
rust-version = "1.38"
14-
edition = "2018"
13+
rust-version = "1.56"
14+
edition = "2021"
1515

1616
[dependencies]
17-
bitflags = "1.2.1"
17+
bitflags = "2"
1818
pcsc-sys = { version = "1.2.0", path = "../pcsc-sys" }

pcsc/src/lib.rs

+28
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ const DUMMY_DWORD: DWORD = 0xdead_beef;
124124

125125
bitflags! {
126126
/// A mask of the state a card reader.
127+
// Derives to keep backward compat with bitflags 1.
128+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
127129
pub struct State: DWORD {
128130
const UNAWARE = ffi::SCARD_STATE_UNAWARE;
129131
const IGNORE = ffi::SCARD_STATE_IGNORE;
@@ -140,6 +142,14 @@ bitflags! {
140142
}
141143
}
142144

145+
// Backward compat with bitflags 1.
146+
impl State {
147+
#[deprecated = "use the safe `from_bits_retain` method instead"]
148+
pub unsafe fn from_bits_unchecked(bits: DWORD) -> Self {
149+
Self::from_bits_retain(bits)
150+
}
151+
}
152+
143153
bitflags! {
144154
/// A mask of the status of a card in a card reader.
145155
///
@@ -148,6 +158,8 @@ bitflags! {
148158
/// On Windows, Status always has exactly one bit set, and the bit values do
149159
/// not correspond to underlying PC/SC constants. This allows Status to be
150160
/// used in the same way across all platforms.
161+
// Derives to keep backward compat with bitflags 1.
162+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
151163
pub struct Status: DWORD {
152164
const UNKNOWN = {
153165
#[cfg(not(target_os = "windows"))] { ffi::SCARD_UNKNOWN }
@@ -197,6 +209,12 @@ impl Status {
197209
#[cfg(not(target_os = "windows"))]
198210
Status::from_bits_truncate(raw_status)
199211
}
212+
213+
// Backward compat with bitflags 1.
214+
#[deprecated = "use the safe `from_bits_retain` method instead"]
215+
pub unsafe fn from_bits_unchecked(bits: DWORD) -> Self {
216+
Self::from_bits_retain(bits)
217+
}
200218
}
201219

202220
/// How a reader connection is shared.
@@ -239,6 +257,8 @@ impl Protocol {
239257

240258
bitflags! {
241259
/// A mask of possible communication protocols.
260+
// Derives to keep backward compat with bitflags 1.
261+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
242262
pub struct Protocols: DWORD {
243263
const UNDEFINED = ffi::SCARD_PROTOCOL_UNDEFINED;
244264
const T0 = ffi::SCARD_PROTOCOL_T0;
@@ -248,6 +268,14 @@ bitflags! {
248268
}
249269
}
250270

271+
// Backward compat with bitflags 1.
272+
impl Protocols {
273+
#[deprecated = "use the safe `from_bits_retain` method instead"]
274+
pub unsafe fn from_bits_unchecked(bits: DWORD) -> Self {
275+
Self::from_bits_retain(bits)
276+
}
277+
}
278+
251279
/// Disposition method when disconnecting from a card reader.
252280
#[repr(u32)]
253281
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)