bitbelay_report/
section.rs

1//! Sections within a [`Report`](super::Report).
2
3pub mod test;
4
5pub use test::Test;
6
7/// A section within a report.
8#[derive(Debug)]
9pub enum Section {
10    /// A test result section.
11    TestResult(Test),
12}
13
14impl Section {
15    /// Returns a refernece to a [`Some(TestResult)`] if the [`Section`] is of
16    /// type [`Section::TestResult`]. Else, returns [`None`].
17    ///
18    /// # Examples
19    ///
20    /// ```
21    /// use bitbelay_report::section::test::module::Result;
22    /// use bitbelay_report::section::test::Builder;
23    /// use bitbelay_report::section::test::Module;
24    /// use bitbelay_report::Section;
25    ///
26    /// let result = Builder::default()
27    ///     .title("Foo")?
28    ///     .description("Bar")?
29    ///     .push_module(Module::new(Result::Inconclusive, "Baz", None, None))
30    ///     .try_build()?;
31    ///
32    /// let section = Section::TestResult(result);
33    /// assert!(matches!(section.as_test_result(), Some(_)));
34    ///
35    /// # Ok::<(), Box<dyn std::error::Error>>(())
36    /// ```
37    pub fn as_test_result(&self) -> Option<&Test> {
38        match self {
39            Section::TestResult(result) => Some(result),
40        }
41    }
42}