From 9e8ce5f8d93d64b437f2da43fcbad954d1e8d601 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 2 Sep 2021 14:37:32 -0700 Subject: [PATCH] Split `next_id()` logic into function --- src/notifications.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/notifications.rs b/src/notifications.rs index 10e7c87d..7049bd1b 100644 --- a/src/notifications.rs +++ b/src/notifications.rs @@ -74,6 +74,14 @@ impl Notifications { notifications } + fn next_id(&self) -> NonZeroU32 { + let mut next_id = self.next_id.lock().unwrap(); + let id = *next_id; + *next_id = NonZeroU32::new(u32::from(*next_id).wrapping_add(1)) + .unwrap_or(NonZeroU32::new(1).unwrap()); + id + } + fn notify( &self, _app_name: String, @@ -85,13 +93,7 @@ impl Notifications { _hints: HashMap, _expire_timeout: i32, ) -> NonZeroU32 { - let id = replaces_id.unwrap_or_else(|| { - let mut next_id = self.next_id.lock().unwrap(); - let id = *next_id; - *next_id = NonZeroU32::new(u32::from(*next_id).wrapping_add(1)) - .unwrap_or(NonZeroU32::new(1).unwrap()); - id - }); + let id = replaces_id.unwrap_or_else(|| self.next_id()); // TODO