github_actions/
group.rs

1fn start_group(title: &str) {
2    println!(
3        "{}",
4        crate::Command {
5            command: "group",
6            value: title,
7            properties: None
8        }
9    );
10}
11
12fn end_group() {
13    println!(
14        "{}",
15        crate::Command {
16            command: "endgroup",
17            value: "",
18            properties: None
19        }
20    );
21}
22
23pub struct Group;
24
25impl Group {
26    pub fn new(title: &str) -> Self {
27        start_group(title);
28        Self {}
29    }
30
31    pub fn end(&self) {
32        end_group();
33    }
34}
35
36pub struct GroupEnder<'a> {
37    group: &'a Group,
38}
39
40impl<'a> GroupEnder<'a> {
41    pub fn new(group: &'a Group) -> Self {
42        Self { group }
43    }
44}
45
46impl Drop for GroupEnder<'_> {
47    fn drop(&mut self) {
48        self.group.end();
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test() {
58        {
59            let group = Group::new("group 1");
60            let _group_ender = GroupEnder::new(&group);
61        }
62        {
63            let _group = Group::new("group 2");
64            // it doesn't end
65        }
66    }
67}