github_actions/
stop_commands.rs1fn start_stop_commands(token: &str) {
2 println!(
3 "{}",
4 crate::Command {
5 command: "stop-commands",
6 value: token,
7 properties: None
8 }
9 );
10}
11
12fn end_stop_commands(token: &str) {
13 println!(
14 "{}",
15 crate::Command {
16 command: token,
17 value: "",
18 properties: None
19 }
20 );
21}
22
23pub struct StopCommands<T: AsRef<str>> {
24 token: T,
25}
26
27impl<T: AsRef<str>> StopCommands<T> {
28 pub fn new(token: T) -> Self {
29 start_stop_commands(token.as_ref());
30 Self { token }
31 }
32
33 pub fn end(&self) {
34 end_stop_commands(self.token.as_ref());
35 }
36}
37
38impl StopCommands<String> {
39 pub fn gen() -> Self {
40 StopCommands::<String>::new(uuid::Uuid::new_v4().to_string())
41 }
42}
43
44pub struct StopCommandsEnder<'a, T: AsRef<str>> {
45 parent: &'a StopCommands<T>,
46}
47
48impl<'a, T: AsRef<str>> StopCommandsEnder<'a, T> {
49 pub fn new(stop_commands: &'a StopCommands<T>) -> Self {
50 Self {
51 parent: stop_commands,
52 }
53 }
54}
55
56impl<'a, T: AsRef<str>> Drop for StopCommandsEnder<'a, T> {
57 fn drop(&mut self) {
58 self.parent.end();
59 }
60}
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn test() {
68 {
69 let stop_cmds = StopCommands::new("token1");
70 let _stop_cmds_ender = StopCommandsEnder::new(&stop_cmds);
71 }
72 {
73 let _stop_cmds = StopCommands::new("token2");
74 }
76 }
77}