Skip to content

Commit 16a11a5

Browse files
cmeisslids1024
authored andcommitted
wayland-server: add alive check to Weak
this allows to check if a resource is still alive without requiring to upgrade the whole resource.
1 parent 2dcf9ab commit 16a11a5

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

wayland-server/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
#### Additions
6+
7+
- Add `Weak::is_alive` allowing to check if a resource is still alive.
8+
59
## 0.31.1 -- 2024-01-29
610

711
- Dropped `nix` dependency in favor of `rustix`

wayland-server/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,19 @@ impl<I: Resource> Weak<I> {
293293
I::from_id(&d_handle, self.id.clone())
294294
}
295295

296+
/// Check if this resource is still alive
297+
///
298+
/// This will return `false` if either:
299+
/// - the object represented by this handle has already been destroyed at the protocol level
300+
/// - the Wayland connection has already been closed
301+
#[inline]
302+
pub fn is_alive(&self) -> bool {
303+
let Some(handle) = self.handle.upgrade() else {
304+
return false;
305+
};
306+
handle.object_info(self.id.clone()).is_ok()
307+
}
308+
296309
/// The underlying [`ObjectId`]
297310
pub fn id(&self) -> ObjectId {
298311
self.id.clone()

0 commit comments

Comments
 (0)