Skip to content

Commit 7f11fd1

Browse files
committed
sndio: simplify Devices iterator
1 parent 8e7227b commit 7f11fd1

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/host/sndio/mod.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,21 @@ impl From<SndioError> for SupportedStreamConfigsError {
9898
}
9999
}
100100

101-
pub struct Devices {
102-
returned: bool,
101+
pub struct Devices(Option<Device>);
102+
103+
impl Devices {
104+
fn new() -> Self {
105+
Devices(Some(Device::new()))
106+
}
103107
}
104108

105109
impl Iterator for Devices {
106110
type Item = Device;
107-
fn next(&mut self) -> Option<Device> {
108-
if self.returned {
109-
None
110-
} else {
111-
self.returned = true;
112-
Some(Device::new())
113-
}
111+
fn next(&mut self) -> Option<Self::Item> {
112+
self.0.take()
114113
}
115114
}
116115

117-
impl Devices {
118-
fn new() -> Devices {
119-
Devices { returned: false }
120-
}
121-
}
122116

123117
/// The shared state between Device and Stream. Responsible for closing handle when dropped.
124118
struct InnerState {

0 commit comments

Comments
 (0)