Skip to content

Commit 7d0b921

Browse files
committed
Fix the build
1 parent 8a82307 commit 7d0b921

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/contrib/controller.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ pub struct ProcessorChannels<Command, Notification> {
1313
}
1414

1515
impl<Command, Notification> ProcessorChannels<Command, Notification> {
16-
/// Drain and process all pending commands.
17-
pub fn drain_commands(&mut self, mut f: impl FnMut(Command)) {
18-
while let Ok(cmd) = self.commands.pop() {
19-
f(cmd);
20-
}
16+
/// Drain and return an iterator over all pending commands.
17+
pub fn drain_commands(&mut self) -> impl Iterator<Item = Command> + '_ {
18+
std::iter::from_fn(move || self.commands.pop().ok())
2119
}
2220

23-
/// Try to send a notification, ignoring if the buffer is full.
21+
/// Try to send a notification.
2422
///
25-
/// Returns `true` if the notification was sent, `false` if the buffer was full.
26-
pub fn try_notify(&mut self, notification: Notification) -> bool {
27-
self.notifications.push(notification).is_ok()
23+
/// Returns `Ok(())` if the notification was sent, or `Err(notification)` if the buffer was full.
24+
pub fn try_notify(&mut self, notification: Notification) -> Result<(), Notification> {
25+
self.notifications
26+
.push(notification)
27+
.map_err(|rtrb::PushError::Full(n)| n)
2828
}
2929
}
3030

@@ -39,7 +39,9 @@ impl<Command, Notification> Controller<Command, Notification> {
3939
///
4040
/// Returns `Ok(())` if the command was sent, or `Err(command)` if the buffer was full.
4141
pub fn send_command(&mut self, command: Command) -> Result<(), Command> {
42-
self.commands.push(command).map_err(|e| e.into_inner())
42+
self.commands
43+
.push(command)
44+
.map_err(|rtrb::PushError::Full(cmd)| cmd)
4345
}
4446

4547
/// Try to receive a notification from the processor.
@@ -49,11 +51,9 @@ impl<Command, Notification> Controller<Command, Notification> {
4951
self.notifications.pop().ok()
5052
}
5153

52-
/// Drain and process all pending notifications.
53-
pub fn drain_notifications(&mut self, mut f: impl FnMut(Notification)) {
54-
while let Ok(notification) = self.notifications.pop() {
55-
f(notification);
56-
}
54+
/// Drain and return an iterator over all pending notifications.
55+
pub fn drain_notifications(&mut self) -> impl Iterator<Item = Notification> + '_ {
56+
std::iter::from_fn(move || self.notifications.pop().ok())
5757
}
5858
}
5959

0 commit comments

Comments
 (0)