Skip to main content

chunked_wal/wal/
callback.rs

1use std::io;
2use std::sync::mpsc::SyncSender;
3
4/// A trait for handling IO operation callbacks.
5///
6/// This trait defines a mechanism to send IO operation results back to the
7/// caller, typically used for asynchronous IO operations.
8pub trait Callback
9where Self: Send + 'static
10{
11    /// Sends the result of a IO operation back to the caller.
12    ///
13    /// # Arguments
14    ///
15    /// * `res` - The result of the operation, either success (Ok(())) or an IO
16    ///   error
17    fn send(self, res: Result<(), io::Error>);
18}
19
20/// Implementation of the Callback trait for SyncSender.
21///
22/// This allows using a synchronous channel sender as a callback mechanism
23/// for IO operations.
24impl Callback for SyncSender<Result<(), io::Error>> {
25    fn send(self, res: Result<(), io::Error>) {
26        let _ = SyncSender::send(&self, res);
27    }
28}