Skip to content

Commit 5f78dca

Browse files
committed
fix: add unreachable variant to DecoderImpl for no enabled decoders
Co-authored-by: @renski-dev
1 parent a24c005 commit 5f78dca

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/decoder/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,14 @@ enum DecoderImpl<R: Read + Seek> {
119119
Mp3(mp3::Mp3Decoder<R>),
120120
#[cfg(feature = "symphonia")]
121121
Symphonia(symphonia::SymphoniaDecoder, PhantomData<R>),
122+
// This variant is here just to satisfy the compiler when there are no decoders enabled.
123+
// It is unreachable and should never be constructed.
124+
#[allow(dead_code)]
125+
None(Unreachable, PhantomData<R>),
122126
}
123127

128+
enum Unreachable {}
129+
124130
impl<R: Read + Seek> DecoderImpl<R> {
125131
#[inline]
126132
fn next(&mut self) -> Option<Sample> {
@@ -135,6 +141,7 @@ impl<R: Read + Seek> DecoderImpl<R> {
135141
DecoderImpl::Mp3(source) => source.next(),
136142
#[cfg(feature = "symphonia")]
137143
DecoderImpl::Symphonia(source, PhantomData) => source.next(),
144+
DecoderImpl::None(_, _) => unreachable!(),
138145
}
139146
}
140147

@@ -151,6 +158,7 @@ impl<R: Read + Seek> DecoderImpl<R> {
151158
DecoderImpl::Mp3(source) => source.size_hint(),
152159
#[cfg(feature = "symphonia")]
153160
DecoderImpl::Symphonia(source, PhantomData) => source.size_hint(),
161+
DecoderImpl::None(_, _) => unreachable!(),
154162
}
155163
}
156164

@@ -167,6 +175,7 @@ impl<R: Read + Seek> DecoderImpl<R> {
167175
DecoderImpl::Mp3(source) => source.current_span_len(),
168176
#[cfg(feature = "symphonia")]
169177
DecoderImpl::Symphonia(source, PhantomData) => source.current_span_len(),
178+
DecoderImpl::None(_, _) => unreachable!(),
170179
}
171180
}
172181

@@ -183,6 +192,7 @@ impl<R: Read + Seek> DecoderImpl<R> {
183192
DecoderImpl::Mp3(source) => source.channels(),
184193
#[cfg(feature = "symphonia")]
185194
DecoderImpl::Symphonia(source, PhantomData) => source.channels(),
195+
DecoderImpl::None(_, _) => unreachable!(),
186196
}
187197
}
188198

@@ -199,6 +209,7 @@ impl<R: Read + Seek> DecoderImpl<R> {
199209
DecoderImpl::Mp3(source) => source.sample_rate(),
200210
#[cfg(feature = "symphonia")]
201211
DecoderImpl::Symphonia(source, PhantomData) => source.sample_rate(),
212+
DecoderImpl::None(_, _) => unreachable!(),
202213
}
203214
}
204215

@@ -221,6 +232,7 @@ impl<R: Read + Seek> DecoderImpl<R> {
221232
DecoderImpl::Mp3(source) => source.total_duration(),
222233
#[cfg(feature = "symphonia")]
223234
DecoderImpl::Symphonia(source, PhantomData) => source.total_duration(),
235+
DecoderImpl::None(_, _) => unreachable!(),
224236
}
225237
}
226238

@@ -237,6 +249,7 @@ impl<R: Read + Seek> DecoderImpl<R> {
237249
DecoderImpl::Mp3(source) => source.try_seek(pos),
238250
#[cfg(feature = "symphonia")]
239251
DecoderImpl::Symphonia(source, PhantomData) => source.try_seek(pos),
252+
DecoderImpl::None(_, _) => unreachable!(),
240253
}
241254
}
242255
}

0 commit comments

Comments
 (0)