From a2b18b5eead89791cacfae9460aea5bf145e1912 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 13 Aug 2024 12:56:35 +0200 Subject: [PATCH] Add wrapper functions to `bitflags` types This reduces potential breakage for users of this library. See https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md#200 for context. --- src/events.rs | 13 +++++++++++++ src/watches.rs | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/events.rs b/src/events.rs index 1304d88..88473f3 100644 --- a/src/events.rs +++ b/src/events.rs @@ -357,6 +357,19 @@ bitflags! { } } +impl EventMask { + /// Wrapper around [`Self::from_bits_retain`] for backwards compatibility + /// + /// # Safety + /// + /// This function is not actually unsafe. It is just a wrapper around the + /// safe [`Self::from_bits_retain`]. + #[deprecated = "Use the safe `from_bits_retain` method instead"] + pub unsafe fn from_bits_unchecked(bits: u32) -> Self { + Self::from_bits_retain(bits) + } +} + #[cfg(test)] mod tests { diff --git a/src/watches.rs b/src/watches.rs index 339c980..2f0e66f 100644 --- a/src/watches.rs +++ b/src/watches.rs @@ -223,6 +223,19 @@ bitflags! { } } +impl WatchMask { + /// Wrapper around [`Self::from_bits_retain`] for backwards compatibility + /// + /// # Safety + /// + /// This function is not actually unsafe. It is just a wrapper around the + /// safe [`Self::from_bits_retain`]. + #[deprecated = "Use the safe `from_bits_retain` method instead"] + pub unsafe fn from_bits_unchecked(bits: u32) -> Self { + Self::from_bits_retain(bits) + } +} + impl WatchDescriptor { /// Getter method for a watcher's id. ///