Skip to content

Commit 1df1425

Browse files
committed
remove thiserror dependency
1 parent a7f67b3 commit 1df1425

3 files changed

Lines changed: 83 additions & 15 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ minimp3_fixed = { version = "0.5.4", optional = true}
1818
symphonia = { version = "0.5.4", optional = true, default-features = false }
1919
crossbeam-channel = { version = "0.5.8", optional = true }
2020

21-
thiserror = "1.0.49"
2221
rand = { version = "0.8.5", features = ["small_rng"], optional = true }
2322
tracing = { version = "0.1.40", optional = true }
2423

src/decoder/symphonia.rs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::time::Duration;
1+
use core::fmt;
2+
use core::time::Duration;
23
use symphonia::{
34
core::{
45
audio::{AudioBufferRef, SampleBuffer, SignalSpec},
@@ -209,21 +210,57 @@ impl Source for SymphoniaDecoder {
209210
}
210211

211212
/// Error returned when the try_seek implementation of the symphonia decoder fails.
212-
#[derive(Debug, thiserror::Error)]
213+
#[derive(Debug)]
213214
pub enum SeekError {
214215
/// Could not get next packet while refining seek position
215-
#[error("Could not get next packet while refining seek position: {0:?}")]
216216
Refining(symphonia::core::errors::Error),
217217
/// Format reader failed to seek
218-
#[error("Format reader failed to seek: {0:?}")]
219218
BaseSeek(symphonia::core::errors::Error),
220219
/// Decoding failed retrying on the next packet failed
221-
#[error("Decoding failed retrying on the next packet failed: {0:?}")]
222220
Retrying(symphonia::core::errors::Error),
223221
/// Decoding failed on multiple consecutive packets
224-
#[error("Decoding failed on multiple consecutive packets: {0:?}")]
225222
Decoding(symphonia::core::errors::Error),
226223
}
224+
impl fmt::Display for SeekError {
225+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
226+
match self {
227+
SeekError::Refining(err) => {
228+
write!(
229+
f,
230+
"Could not get next packet while refining seek position: {:?}",
231+
err
232+
)
233+
}
234+
SeekError::BaseSeek(err) => {
235+
write!(f, "Format reader failed to seek: {:?}", err)
236+
}
237+
SeekError::Retrying(err) => {
238+
write!(
239+
f,
240+
"Decoding failed retrying on the next packet failed: {:?}",
241+
err
242+
)
243+
}
244+
SeekError::Decoding(err) => {
245+
write!(
246+
f,
247+
"Decoding failed on multiple consecutive packets: {:?}",
248+
err
249+
)
250+
}
251+
}
252+
}
253+
}
254+
impl std::error::Error for SeekError {
255+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
256+
match self {
257+
SeekError::Refining(err) => Some(err),
258+
SeekError::BaseSeek(err) => Some(err),
259+
SeekError::Retrying(err) => Some(err),
260+
SeekError::Decoding(err) => Some(err),
261+
}
262+
}
263+
}
227264

228265
impl SymphoniaDecoder {
229266
/// Note frame offset must be set after

src/source/mod.rs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Sources of sound and various filters.
22
3-
use std::time::Duration;
3+
use core::fmt;
4+
use core::time::Duration;
45

56
use cpal::FromSample;
67

@@ -585,28 +586,59 @@ where
585586
/// Occurs when try_seek fails because the underlying decoder has an error or
586587
/// does not support seeking.
587588
#[non_exhaustive]
588-
#[derive(Debug, thiserror::Error)]
589+
#[derive(Debug)]
589590
pub enum SeekError {
590-
/// On of the underlying sources does not support seeking
591-
#[error("Seeking is not supported by source: {underlying_source}")]
591+
/// One of the underlying sources does not support seeking
592592
NotSupported {
593593
/// The source that did not support seek
594594
underlying_source: &'static str,
595595
},
596596
#[cfg(feature = "symphonia")]
597597
/// The symphonia decoder ran into an issue
598-
#[error("Error seeking: {0}")]
599-
SymphoniaDecoder(#[from] crate::decoder::symphonia::SeekError),
598+
SymphoniaDecoder(crate::decoder::symphonia::SeekError),
600599
#[cfg(feature = "wav")]
601-
#[error("Error seeking in wav source: {0}")]
602600
/// The hound (wav) decoder ran into an issue
603601
HoundDecoder(std::io::Error),
604602
// Prefer adding an enum variant to using this. Its meant for end users their
605603
// own try_seek implementations
606604
/// Any other error probably in a custom Source
607-
#[error("An error occurred")]
608605
Other(Box<dyn std::error::Error + Send>),
609606
}
607+
impl fmt::Display for SeekError {
608+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
609+
match self {
610+
SeekError::NotSupported { underlying_source } => {
611+
write!(
612+
f,
613+
"Seeking is not supported by source: {}",
614+
underlying_source
615+
)
616+
}
617+
#[cfg(feature = "symphonia")]
618+
SeekError::SymphoniaDecoder(err) => write!(f, "Error seeking: {}", err),
619+
#[cfg(feature = "wav")]
620+
SeekError::HoundDecoder(err) => write!(f, "Error seeking in wav source: {}", err),
621+
SeekError::Other(_) => write!(f, "An error occurred"),
622+
}
623+
}
624+
}
625+
impl std::error::Error for SeekError {
626+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
627+
match self {
628+
SeekError::NotSupported { .. } => None,
629+
#[cfg(feature = "symphonia")]
630+
SeekError::SymphoniaDecoder(err) => Some(err),
631+
#[cfg(feature = "wav")]
632+
SeekError::HoundDecoder(err) => Some(err),
633+
SeekError::Other(err) => Some(err.as_ref()),
634+
}
635+
}
636+
}
637+
impl From<crate::decoder::symphonia::SeekError> for SeekError {
638+
fn from(source: crate::decoder::symphonia::SeekError) -> Self {
639+
SeekError::SymphoniaDecoder(source)
640+
}
641+
}
610642

611643
impl SeekError {
612644
/// Will the source remain playing at its position before the seek or is it

0 commit comments

Comments
 (0)