#[non_exhaustive]pub enum LayoutError {
NonContiguous {
operation: String,
layout_type: String,
},
DimensionMismatch {
expected_dims: String,
actual_dims: String,
operation: String,
},
BorrowedDataMutation {
operation: String,
reason: String,
},
IncompatibleFormat {
operation: String,
reason: String,
},
ShapeError {
operation: String,
info: String,
},
InvalidOperation(String, String),
}Expand description
Errors related to memory layout, array structure, and data organization.
§Purpose
Covers failures related to array contiguity, dimension mismatches, borrowed data mutation attempts, and other structural issues that arise from the ndarray-backed storage of audio samples.
§Intended Usage
Return these errors when an operation’s structural preconditions are not met — for example, when a mono-only function receives multi-channel input, or when an in-place operation is attempted on borrowed (non-owned) data.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
NonContiguous
Array data is not contiguous in memory when contiguous layout is required.
Fields
DimensionMismatch
Array dimensions don’t match expected values for the operation.
Fields
BorrowedDataMutation
Attempted to modify borrowed audio data that should be immutable.
Fields
IncompatibleFormat
Data size or format is incompatible with the operation requirements.
Fields
ShapeError
A shape-related error occurred during array operations.
Fields
InvalidOperation(String, String)
Error indicating an invalid operation on audio data.
Occurs when attempting an operation that violates preconditions, such as applying a function to incompatible audio layouts, mismatched dimensions, or invalid state.
Implementations§
Source§impl LayoutError
impl LayoutError
Sourcepub fn invalid_operation<S>(operation: S, reason: S) -> Selfwhere
S: ToString,
pub fn invalid_operation<S>(operation: S, reason: S) -> Selfwhere
S: ToString,
Creates a LayoutError::InvalidOperation error.
Use this when a valid operation is called in a context where it cannot proceed — for example, requesting an STFT on multi-channel audio.
§Arguments
operation— Name of the operation that was called in an invalid context.reason— Human-readable explanation of why the operation cannot proceed (e.g."STFT requires mono audio").
§Returns
LayoutError::InvalidOperation(operation.to_string(), reason.to_string()).
§Examples
use audio_samples::LayoutError;
let err = LayoutError::invalid_operation("stft", "requires mono audio");
assert!(matches!(err, LayoutError::InvalidOperation(_, _)));Source§impl LayoutError
impl LayoutError
Sourcepub fn borrowed_mutation<O, R>(operation: O, reason: R) -> Self
pub fn borrowed_mutation<O, R>(operation: O, reason: R) -> Self
Creates a LayoutError::BorrowedDataMutation error.
Use this when an in-place or mutating operation is attempted on audio data that is held via an immutable borrow and therefore cannot be modified.
§Arguments
operation— Name of the operation that attempted to modify borrowed data.reason— Human-readable explanation of why modification is not allowed.
§Returns
A LayoutError::BorrowedDataMutation variant.
§Examples
use audio_samples::LayoutError;
let err = LayoutError::borrowed_mutation("normalize_in_place", "audio data is borrowed");
assert!(matches!(err, LayoutError::BorrowedDataMutation { .. }));Sourcepub fn dimension_mismatch<E, A, O>(expected: E, actual: A, operation: O) -> Self
pub fn dimension_mismatch<E, A, O>(expected: E, actual: A, operation: O) -> Self
Creates a LayoutError::DimensionMismatch error.
Use this when an array or buffer has the wrong number of dimensions or an unexpected shape for the operation being performed.
§Arguments
expected— Description of the expected dimensions (e.g."(1, 1024)").actual— Description of the actual dimensions received (e.g."(2, 1024)").operation— Name of the operation that has the dimension requirement.
§Returns
A LayoutError::DimensionMismatch variant.
§Examples
use audio_samples::LayoutError;
let err = LayoutError::dimension_mismatch("(1, 1024)", "(2, 1024)", "mono_fft");
assert!(matches!(err, LayoutError::DimensionMismatch { .. }));Trait Implementations§
Source§impl Clone for LayoutError
impl Clone for LayoutError
Source§fn clone(&self) -> LayoutError
fn clone(&self) -> LayoutError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LayoutError
impl Debug for LayoutError
Source§impl Display for LayoutError
impl Display for LayoutError
Source§impl Error for LayoutError
impl Error for LayoutError
1.30.0 · 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
use the Display impl or to_string()
Source§impl From<LayoutError> for AudioSampleError
impl From<LayoutError> for AudioSampleError
Source§fn from(source: LayoutError) -> Self
fn from(source: LayoutError) -> Self
Auto Trait Implementations§
impl Freeze for LayoutError
impl RefUnwindSafe for LayoutError
impl Send for LayoutError
impl Sync for LayoutError
impl Unpin for LayoutError
impl UnsafeUnpin for LayoutError
impl UnwindSafe for LayoutError
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