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