rodio/source/
empty.rs

1use std::time::Duration;
2
3use super::SeekError;
4use crate::common::{ChannelCount, SampleRate};
5use crate::{Sample, Source};
6
7/// An empty source.
8#[derive(Debug, Copy, Clone)]
9pub struct Empty();
10
11impl Default for Empty {
12    #[inline]
13    fn default() -> Self {
14        Self::new()
15    }
16}
17
18impl Empty {
19    /// An empty source that immediately ends without ever returning a sample to
20    /// play
21    #[inline]
22    pub fn new() -> Empty {
23        Empty()
24    }
25}
26
27impl Iterator for Empty {
28    type Item = Sample;
29
30    #[inline]
31    fn next(&mut self) -> Option<Self::Item> {
32        None
33    }
34}
35
36impl Source for Empty {
37    #[inline]
38    fn current_span_len(&self) -> Option<usize> {
39        None
40    }
41
42    #[inline]
43    fn channels(&self) -> ChannelCount {
44        1
45    }
46
47    #[inline]
48    fn sample_rate(&self) -> SampleRate {
49        48000
50    }
51
52    #[inline]
53    fn total_duration(&self) -> Option<Duration> {
54        Some(Duration::new(0, 0))
55    }
56
57    #[inline]
58    fn try_seek(&mut self, _: Duration) -> Result<(), SeekError> {
59        Err(SeekError::NotSupported {
60            underlying_source: std::any::type_name::<Self>(),
61        })
62    }
63}