|
15 | 15 | // with this program; if not, write to the Free Software Foundation, Inc.,
|
16 | 16 | // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
17 | 17 |
|
| 18 | +use std::fmt::Write; |
18 | 19 | use std::io::Result;
|
19 | 20 | use std::time::Duration;
|
20 | 21 |
|
@@ -134,15 +135,19 @@ impl Pattern for Leds {
|
134 | 135 | fn set_pattern(&self, pattern: BlinkPattern) -> Result<()> {
|
135 | 136 | let max = self.max_brightness()? as f32;
|
136 | 137 | let repetitions = pattern.repetitions;
|
137 |
| - let pattern: String = pattern |
138 |
| - .steps |
139 |
| - .iter() |
140 |
| - .map(|(brightness, duration)| { |
141 |
| - let brightness = (brightness * max).round(); |
142 |
| - let duration = duration.as_millis(); |
143 |
| - format!("{} {} ", brightness, duration) |
144 |
| - }) |
145 |
| - .collect(); |
| 138 | + let pattern = |
| 139 | + pattern |
| 140 | + .steps |
| 141 | + .iter() |
| 142 | + .fold(String::new(), |mut dst, (brightness, duration)| { |
| 143 | + let brightness = (brightness * max).round(); |
| 144 | + let duration = duration.as_millis(); |
| 145 | + |
| 146 | + write!(dst, "{} {} ", brightness, duration) |
| 147 | + .expect("Writing to a String should never fail"); |
| 148 | + |
| 149 | + dst |
| 150 | + }); |
146 | 151 |
|
147 | 152 | self.write_file("trigger", "pattern")?;
|
148 | 153 | self.write_file("pattern", pattern)?;
|
|
0 commit comments