| 1 | /// A platform-independent notification identifier. |
| 2 | /// |
| 3 | /// On XDG (Linux/BSD) notifications are identified by a server-assigned `u32`. |
| 4 | /// On macOS (`preview-macos-un`) they use a caller-supplied `String`. |
| 5 | /// |
| 6 | /// Both variants implement `From`, so you can pass either type directly to |
| 7 | /// [`Notification::id`](crate::Notification::id): |
| 8 | /// |
| 9 | /// ```no_run |
| 10 | /// # use notify_rust::Notification; |
| 11 | /// // XDG — pass a u32 |
| 12 | /// # #[cfg(all(unix, not(target_os = "macos")))] |
| 13 | /// Notification::new().id(42u32).show().unwrap(); |
| 14 | /// |
| 15 | /// // macOS — pass a &str or String |
| 16 | /// # #[cfg(all(target_os = "macos", feature = "preview-macos-un"))] |
| 17 | /// Notification::new().id("my-app.status").show().unwrap(); |
| 18 | /// ``` |
| 19 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 20 | pub enum NotificationId { |
| 21 | /// XDG / D-Bus numeric identifier (Linux, BSD). |
| 22 | Xdg(u32), |
| 23 | |
| 24 | /// macOS `UNNotificationRequest` string identifier. |
| 25 | Mac(String), |
| 26 | } |
| 27 | |
| 28 | impl From<u32> for NotificationId { |
| 29 | fn from(value: u32) -> Self { |
| 30 | NotificationId::Xdg(value) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | impl From<String> for NotificationId { |
| 35 | fn from(value: String) -> Self { |
| 36 | NotificationId::Mac(value) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | impl From<&str> for NotificationId { |
| 41 | fn from(value: &str) -> Self { |
| 42 | NotificationId::Mac(value.to_owned()) |
| 43 | } |
| 44 | } |