ltpp_output/output_list/
impl.rs

1use std::ops::Deref;
2use std::slice::Iter;
3use std::vec;
4
5use crate::{ColorType, Output, OutputList};
6
7use crate::output;
8
9impl<'a> Default for OutputList<'a> {
10    /// Provides a default implementation for `OutputList`.
11    ///
12    /// # Returns
13    /// - `OutputList<'a>`: Returns an `OutputList` containing a default `Output`.
14    fn default() -> Self {
15        OutputList(vec![Output::<'a>::default()])
16    }
17}
18
19impl<'a> Deref for OutputList<'a> {
20    type Target = Vec<Output<'a>>;
21
22    /// Dereferences `OutputList` to its internal `Vec<Output<'a>>`.
23    ///
24    /// # Returns
25    /// - `&Vec<Output<'a>>`: A reference to the internal vector of outputs.
26    fn deref(&self) -> &Self::Target {
27        &self.0
28    }
29}
30
31impl<'a> IntoIterator for &'a OutputList<'a> {
32    type Item = &'a Output<'a>;
33    type IntoIter = Iter<'a, Output<'a>>;
34
35    /// Returns an iterator over the elements of the internal `Vec<Output<'a>>`.
36    ///
37    /// # Returns
38    /// - `Iter<'a, Output<'a>>`: An iterator over references to the `Output` elements.
39    fn into_iter(self) -> Self::IntoIter {
40        self.0.iter()
41    }
42}
43
44impl<'a> OutputList<'a> {
45    /// Provides an iterator over the elements in the internal `Vec<Output<'a>>`.
46    ///
47    /// # Returns
48    /// - `Iter<'_, Output<'a>>`: An iterator over references to `Output` elements.
49    pub fn iter(&self) -> std::slice::Iter<'_, Output<'a>> {
50        self.0.iter()
51    }
52
53    /// Outputs the content of each `Output` in the list.
54    ///
55    /// This method clones the `OutputList` and iterates through its elements, calling the `output` method on each cloned `Output`.
56    ///
57    /// # Returns
58    /// - `()` : Nothing is returned.
59    pub fn output(self) {
60        let output_list: OutputList<'a> = self.clone();
61        for output in &output_list {
62            output.clone().output();
63        }
64    }
65}