Skip to content

Commit 0ec450e

Browse files
committed
Decided not to deprecate into_array
into_array provides some compatibility between this crate and the defunct F3 crate. It should stay with a strong encouragement to not use it. Also added a few doc examples.
1 parent 331b726 commit 0ec450e

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

src/leds.rs

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ impl Leds {
118118
}
119119

120120
/// Mutably borrow a LED by the given direction (as noted on the board)
121+
///
122+
/// # Example
123+
///
124+
/// ```
125+
/// let southLed = leds.for_direction(Direction::South);
126+
/// southLed.on().ok();
127+
/// ```
121128
pub fn for_direction(&mut self, direction: Direction) -> &mut Led {
122129
match direction {
123130
Direction::North => &mut self.ld3,
@@ -132,16 +139,49 @@ impl Leds {
132139
}
133140

134141
/// Provides a mutable iterator for iterating over the on board leds.
135-
/// Starts at ld3 (N) and moves clockwise.
142+
/// Starts at ld3 (N) and moves clockwise.
136143
/// Stops once it has iterated through all 8 leds.
144+
///
145+
/// # Examples
146+
///
147+
/// Iterate over the leds clockwise
148+
///
149+
/// ```
150+
/// let ms_delay = 50u16;
151+
/// for led in &mut leds {
152+
/// led.on().ok();
153+
/// delay.delay_ms(ms_delay);
154+
/// led.off().ok();
155+
/// delay.delay_ms(ms_delay);
156+
/// }
157+
/// ```
158+
///
159+
/// Iterate over the leds counter clockwise
160+
///
161+
/// ```
162+
/// let ms_delay = 50u16;
163+
/// for led in leds.iter_mut().rev() {
164+
/// led.on().ok();
165+
/// delay.delay_ms(ms_delay);
166+
/// led.off().ok();
167+
/// delay.delay_ms(ms_delay);
168+
/// }
169+
/// ```
137170
pub fn iter_mut(&mut self) -> LedsMutIterator {
138171
LedsMutIterator::new(self)
139172
}
140173

141-
/// Consumes the `Leds` struct and returns an array
142-
/// where index 0 is N and each incrementing index
143-
/// rotates clockwise around the compass
144-
#[deprecated(since = "0.7.1", note = "Use `iter_mut()` intsead. This will be removed in 0.8.0")]
174+
/// Consumes the `Leds` struct and returns an array,
175+
/// where index 0 is N and each incrementing index.
176+
/// Rotates clockwise around the compass.
177+
///
178+
/// # Warning
179+
///
180+
/// This function is maintained solely for some level of compatibility with the old F3 crate.
181+
///
182+
/// [`Self::iter_mut()`] should be prefered.
183+
/// Testing suggests that using [`Self::iter_mut()`] results in an ~800 byte
184+
/// reduction in final binary size.
145185
pub fn into_array(self) -> [Led; 8] {
146186
[
147187
self.ld3, //N

0 commit comments

Comments
 (0)