|
1 | 1 | //! Sources of sound and various filters. |
2 | 2 |
|
3 | | -use std::time::Duration; |
| 3 | +use core::fmt; |
| 4 | +use core::time::Duration; |
4 | 5 |
|
5 | 6 | use cpal::FromSample; |
6 | 7 |
|
@@ -585,28 +586,59 @@ where |
585 | 586 | /// Occurs when try_seek fails because the underlying decoder has an error or |
586 | 587 | /// does not support seeking. |
587 | 588 | #[non_exhaustive] |
588 | | -#[derive(Debug, thiserror::Error)] |
| 589 | +#[derive(Debug)] |
589 | 590 | 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 |
592 | 592 | NotSupported { |
593 | 593 | /// The source that did not support seek |
594 | 594 | underlying_source: &'static str, |
595 | 595 | }, |
596 | 596 | #[cfg(feature = "symphonia")] |
597 | 597 | /// 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), |
600 | 599 | #[cfg(feature = "wav")] |
601 | | - #[error("Error seeking in wav source: {0}")] |
602 | 600 | /// The hound (wav) decoder ran into an issue |
603 | 601 | HoundDecoder(std::io::Error), |
604 | 602 | // Prefer adding an enum variant to using this. Its meant for end users their |
605 | 603 | // own try_seek implementations |
606 | 604 | /// Any other error probably in a custom Source |
607 | | - #[error("An error occurred")] |
608 | 605 | Other(Box<dyn std::error::Error + Send>), |
609 | 606 | } |
| 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 | +} |
610 | 642 |
|
611 | 643 | impl SeekError { |
612 | 644 | /// Will the source remain playing at its position before the seek or is it |
|
0 commit comments