use crate::NodeId;
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum FlushError {
#[error("ring full (xrun): {0} frame(s) dropped")]
RingFull(usize),
#[error("node {0} is not a flushable sink")]
NotFlushable(NodeId),
#[error("node {0} not found")]
NodeNotFound(NodeId),
}
pub trait Flushable {
fn flush(&mut self) -> Result<(), FlushError>;
}
pub trait SinkNode: audio_core_bsd::AudioNode + Flushable {}
impl<T> SinkNode for T where T: audio_core_bsd::AudioNode + Flushable {}
#[cfg(test)]
mod tests {
use super::FlushError;
#[test]
fn flush_error_display() {
assert_eq!(
FlushError::RingFull(3).to_string(),
"ring full (xrun): 3 frame(s) dropped"
);
assert_eq!(
FlushError::NotFlushable(7).to_string(),
"node 7 is not a flushable sink"
);
assert_eq!(
FlushError::NodeNotFound(2).to_string(),
"node 2 not found"
);
}
#[test]
fn flush_error_clone_eq() {
let e = FlushError::RingFull(1);
assert_eq!(e.clone(), e);
assert_ne!(FlushError::RingFull(1), FlushError::NodeNotFound(1));
}
}