Implement network manager simulator lifecycle (#53)
All checks were successful
Native code generation / deterministic (push) Successful in 8m55s
Imaging and meshing gate / native (push) Successful in 2m45s
JPEG 2000 feature / linux (push) Successful in 1m41s
Native Rust workspace compile / compile (push) Successful in 1m57s
Skia feature / linux (push) Successful in 31m12s

This commit is contained in:
2026-08-09 14:46:34 +00:00
parent a18b09d928
commit d298b4f4c4
13 changed files with 3840 additions and 588 deletions

View File

@@ -466,8 +466,61 @@ impl Drop for CancellationRegistration {
}
}
#[derive(Debug, Default, Eq, Hash, PartialEq)]
pub struct Subscription;
/// RAII guard for a mapped event subscription.
///
/// Dropping or explicitly closing the guard invokes the removal callback once.
/// The callback normally owns only a weak reference to the event registry, so
/// an abandoned subscription cannot keep its publisher alive.
#[must_use = "dropping the subscription immediately unregisters the handler"]
pub struct Subscription {
close: Option<Box<dyn FnOnce() + Send + Sync>>,
}
impl Subscription {
pub fn new(close: impl FnOnce() + Send + Sync + 'static) -> Self {
Self {
close: Some(Box::new(close)),
}
}
pub fn close(mut self) {
if let Some(close) = self.close.take() {
close();
}
}
#[must_use]
pub const fn is_active(&self) -> bool {
self.close.is_some()
}
pub const fn detached() -> Self {
Self { close: None }
}
}
impl Default for Subscription {
fn default() -> Self {
Self::detached()
}
}
impl fmt::Debug for Subscription {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter
.debug_struct("Subscription")
.field("active", &self.is_active())
.finish()
}
}
impl Drop for Subscription {
fn drop(&mut self) {
if let Some(close) = self.close.take() {
close();
}
}
}
pub type EventHandler<T> = Arc<dyn Fn(T) + Send + Sync>;