Skip to content

Commit

Permalink
wayland-server: add alive check to Weak
Browse files Browse the repository at this point in the history
this allows to check if a resource is still alive
without requiring to upgrade the whole resource.
  • Loading branch information
cmeissl committed May 8, 2024
1 parent 8035543 commit d768d5e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions wayland-server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

#### Additions

- Add `Weak::is_alive` allowing to check if a resource is still alive.

## 0.31.1 -- 2024-01-29

- Dropped `nix` dependency in favor of `rustix`
Expand Down
13 changes: 13 additions & 0 deletions wayland-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,19 @@ impl<I: Resource> Weak<I> {
I::from_id(&d_handle, self.id.clone())
}

/// Check if this resource is still alive
///
/// This will return `false` if either:
/// - the object represented by this handle has already been destroyed at the protocol level
/// - the Wayland connection has already been closed
#[inline]
pub fn is_alive(&self) -> bool {
let Some(handle) = self.handle.upgrade() else {
return false;
};
handle.object_info(self.id.clone()).is_ok()
}

/// The underlying [`ObjectId`]
pub fn id(&self) -> ObjectId {
self.id.clone()
Expand Down

0 comments on commit d768d5e

Please sign in to comment.