#[non_exhaustive]pub enum AudioSampleError {
Conversion(ConversionError),
Parameter(ParameterError),
Layout(LayoutError),
Processing(ProcessingError),
Feature(FeatureError),
Parse {
type_name: String,
context: String,
},
EmptyData,
InvalidNumberOfSamples {
total_samples: usize,
channels: u32,
},
Fmt(Error),
Unsupported(String),
}Expand description
Root error type for all audio sample operations.
§Purpose
AudioSampleError is the single error type returned by every fallible
public API in this crate. It groups failures into five sub-domains so that
callers can handle broad categories with a single match arm while retaining
the ability to inspect specific variants when required.
§Intended Usage
Prefer matching on the inner sub-type rather than the outer variant wherever
the specific failure domain matters. Propagate errors out of functions using
the ? operator together with the AudioSampleResult return type.
§Invariants
The enum is #[non_exhaustive], meaning new variants may be added in future
minor versions. Always include a catch-all arm when matching exhaustively.
§Feature-gated variants
The Spectrogram variant is only present when the transforms feature is
enabled. It wraps errors originating from the spectrograms crate.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Conversion(ConversionError)
Errors related to type conversions and casting operations.
Parameter(ParameterError)
Errors related to invalid parameters or configuration.
Layout(LayoutError)
Errors related to memory layout, array structure, or data organization.
Processing(ProcessingError)
Errors that occur during audio processing operations.
Feature(FeatureError)
Errors related to missing or disabled features.
Parse
Errors related to parsing of any of the various audio_samples support types.
Fields
EmptyData
Error indicating that audio data is empty when non-empty data is required.
InvalidNumberOfSamples
Error indicating mismatch between total samples and channel count.
Occurs when the total number of samples is not evenly divisible by the number of channels, indicating malformed or corrupted audio data.
Fmt(Error)
Error indicating a formatting failure during display or debug output.
Unsupported(String)
Error indicating an unsupported operation or configuration.
Used when a requested operation is valid in principle but not implemented for the given combination of inputs (e.g., certain multi-channel operations, unsupported sample types, or platform-specific limitations).
Implementations§
Source§impl AudioSampleError
impl AudioSampleError
Sourcepub fn unsupported<S>(msg: S) -> Selfwhere
S: ToString,
pub fn unsupported<S>(msg: S) -> Selfwhere
S: ToString,
Creates an crate::AudioSampleError::Unsupported with the given message.
Use this when a caller requests an operation that is valid in principle but not implemented for the given combination of inputs (e.g. multi-channel STFT).
§Arguments
msg— Human-readable description of the unsupported operation.
§Returns
AudioSampleError::Unsupported(msg.to_string()).
§Examples
use audio_samples::AudioSampleError;
let err = AudioSampleError::unsupported("multi-channel MFCC is not supported");
assert!(matches!(err, AudioSampleError::Unsupported(_)));Sourcepub const fn invalid_number_of_samples(
total_samples: usize,
channels: u32,
) -> Self
pub const fn invalid_number_of_samples( total_samples: usize, channels: u32, ) -> Self
Creates an AudioSampleError::InvalidNumberOfSamples error.
Use this when total_samples cannot be distributed evenly across
channels, or when the combination is otherwise incoherent for the
requested layout.
§Arguments
total_samples— The total number of interleaved samples provided.channels— The number of audio channels requested.
§Returns
AudioSampleError::InvalidNumberOfSamples { total_samples, channels }.
§Examples
use audio_samples::AudioSampleError;
// 5 samples cannot be divided evenly into 2 channels
let err = AudioSampleError::invalid_number_of_samples(5, 2);
assert!(matches!(err, AudioSampleError::InvalidNumberOfSamples { .. }));Sourcepub fn parse<T, S>(msg: S) -> Selfwhere
S: ToString,
pub fn parse<T, S>(msg: S) -> Selfwhere
S: ToString,
Creates an AudioSampleError::Parse error for the type T.
The type name of T is captured automatically via
std::any::type_name and embedded in the returned error for
diagnostic purposes.
§Arguments
msg— Human-readable description of the parse failure.
§Type Parameters
T— The type that could not be parsed. Its name is recorded in thetype_namefield of the returned error.
§Returns
AudioSampleError::Parse { type_name: std::any::type_name::<T>(), context: msg }.
§Examples
use audio_samples::AudioSampleError;
let err = AudioSampleError::parse::<f32, _>("expected a finite float");
assert!(matches!(err, AudioSampleError::Parse { .. }));Sourcepub fn layout<S>(msg: S) -> Selfwhere
S: ToString,
pub fn layout<S>(msg: S) -> Selfwhere
S: ToString,
Creates an crate::AudioSampleError::Layout wrapping a
LayoutError::ShapeError.
Convenience constructor for shape-related layout errors where the
specific operation name is not available at the call site. The
operation field is set to "unknown".
§Arguments
msg— Human-readable description of the shape problem.
§Returns
AudioSampleError::Layout(LayoutError::ShapeError { operation: "unknown", info: msg }).
§Examples
use audio_samples::{AudioSampleError, LayoutError};
let err = AudioSampleError::layout("expected 2-D array, got 3-D");
assert!(matches!(err, AudioSampleError::Layout(LayoutError::ShapeError { .. })));Trait Implementations§
Source§impl Clone for AudioSampleError
impl Clone for AudioSampleError
Source§fn clone(&self) -> AudioSampleError
fn clone(&self) -> AudioSampleError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AudioSampleError
impl Debug for AudioSampleError
Source§impl Display for AudioSampleError
impl Display for AudioSampleError
Source§impl Error for AudioSampleError
impl Error for AudioSampleError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<ConversionError> for AudioSampleError
impl From<ConversionError> for AudioSampleError
Source§fn from(source: ConversionError) -> Self
fn from(source: ConversionError) -> Self
Source§impl From<Error> for AudioSampleError
impl From<Error> for AudioSampleError
Source§impl From<FeatureError> for AudioSampleError
impl From<FeatureError> for AudioSampleError
Source§fn from(source: FeatureError) -> Self
fn from(source: FeatureError) -> Self
Source§impl From<LayoutError> for AudioSampleError
impl From<LayoutError> for AudioSampleError
Source§fn from(source: LayoutError) -> Self
fn from(source: LayoutError) -> Self
Source§impl From<ParameterError> for AudioSampleError
impl From<ParameterError> for AudioSampleError
Source§fn from(source: ParameterError) -> Self
fn from(source: ParameterError) -> Self
Source§impl From<ProcessingError> for AudioSampleError
impl From<ProcessingError> for AudioSampleError
Source§fn from(source: ProcessingError) -> Self
fn from(source: ProcessingError) -> Self
Source§impl From<ShapeError> for AudioSampleError
impl From<ShapeError> for AudioSampleError
Source§fn from(err: ShapeError) -> Self
fn from(err: ShapeError) -> Self
Auto Trait Implementations§
impl Freeze for AudioSampleError
impl RefUnwindSafe for AudioSampleError
impl Send for AudioSampleError
impl Sync for AudioSampleError
impl Unpin for AudioSampleError
impl UnsafeUnpin for AudioSampleError
impl UnwindSafe for AudioSampleError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Src, Dst> ConvertTo<Dst> for Srcwhere
Dst: ConvertFrom<Src>,
impl<Src, Dst> ConvertTo<Dst> for Srcwhere
Dst: ConvertFrom<Src>,
Source§fn convert_to(self) -> Dst
fn convert_to(self) -> Dst
Dst using audio-aware scaling. Read more