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