termux_notification/
remove_handle.rs1use std::{io, process::Command};
2
3use super::ensure_success;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct RemoveHandle {
8 id: Option<String>,
9}
10
11impl RemoveHandle {
12 #[must_use]
13 pub fn new(id: Option<String>) -> Self {
14 Self { id }
15 }
16
17 #[must_use]
18 pub fn id(&self) -> Option<&String> {
19 self.id.as_ref()
20 }
21
22 pub fn remove(&self) -> io::Result<()> {
28 if let Some(mut cmd) = self.to_command() {
29 ensure_success(&cmd.output()?)?;
30 }
31 Ok(())
32 }
33
34 #[must_use]
36 pub fn to_command(&self) -> Option<Command> {
37 let mut cmd = Command::new("termux-notification-remove");
38 cmd.arg(self.id()?);
39 Some(cmd)
40 }
41}