#[non_exhaustive]pub enum ConversionError {
AudioConversion {
value: String,
source_type: String,
target_type: String,
reason: String,
},
NumericCast {
value: String,
source_type: String,
target_type: String,
reason: String,
},
UnsupportedConversion {
source_type: String,
target_type: String,
},
}Expand description
Errors that occur during type conversion and casting operations.
§Purpose
Covers both audio-aware conversions (e.g. i16 ↔ f32 with normalisation)
and raw numeric casts between sample types. The distinction between
AudioConversion and
NumericCast reflects whether the
operation understood audio semantics.
§Intended Usage
Returned by to_format, to_type, cast_as, and cast_to. Prefer the
audio-aware variants (to_format, to_type) over raw casts unless you
deliberately need non-normalised bit patterns.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
AudioConversion
Failed to convert between audio sample types with audio-aware scaling.
Fields
NumericCast
Failed to perform raw numeric casting between types.
Fields
UnsupportedConversion
The conversion operation is not supported between the specified types.
Implementations§
Source§impl ConversionError
impl ConversionError
Sourcepub fn audio_conversion<V, S, T, R>(
value: V,
source_type: S,
target_type: T,
reason: R,
) -> Self
pub fn audio_conversion<V, S, T, R>( value: V, source_type: S, target_type: T, reason: R, ) -> Self
Creates a ConversionError::AudioConversion error.
Use this when an audio-aware type conversion fails — for example, when a normalised float value cannot be represented in the target integer type.
§Arguments
value— The sample value that failed to convert (converted to string for display).source_type— Name of the source sample type (e.g."i16").target_type— Name of the target sample type (e.g."f32").reason— Human-readable explanation of why the conversion failed.
§Returns
A ConversionError::AudioConversion variant.
§Examples
use audio_samples::{AudioSampleError, ConversionError};
let err = ConversionError::audio_conversion("32768", "i16", "i8", "value out of range");
assert!(matches!(err, ConversionError::AudioConversion { .. }));
// Wraps into the root error type via the From impl.
let audio_err: AudioSampleError = err.into();
assert!(matches!(audio_err, AudioSampleError::Conversion(_)));Sourcepub fn numeric_cast<V, S, T, R>(
value: V,
source_type: S,
target_type: T,
reason: R,
) -> Self
pub fn numeric_cast<V, S, T, R>( value: V, source_type: S, target_type: T, reason: R, ) -> Self
Creates a ConversionError::NumericCast error.
Use this when a raw numeric cast fails — for example, when casting a
large f64 value to u8 would overflow or produce a meaningless bit
pattern.
§Arguments
value— The numeric value that failed to cast (converted to string for display).source_type— Name of the source numeric type (e.g."f64").target_type— Name of the target numeric type (e.g."u8").reason— Human-readable explanation of why the cast failed.
§Returns
A ConversionError::NumericCast variant.
§Examples
use audio_samples::ConversionError;
let err = ConversionError::numeric_cast("300.0", "f64", "u8", "value exceeds 255");
assert!(matches!(err, ConversionError::NumericCast { .. }));Trait Implementations§
Source§impl Clone for ConversionError
impl Clone for ConversionError
Source§fn clone(&self) -> ConversionError
fn clone(&self) -> ConversionError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ConversionError
impl Debug for ConversionError
Source§impl Display for ConversionError
impl Display for ConversionError
Source§impl Error for ConversionError
impl Error for ConversionError
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
Source§impl From<ConversionError> for AudioSampleError
impl From<ConversionError> for AudioSampleError
Source§fn from(source: ConversionError) -> Self
fn from(source: ConversionError) -> Self
Auto Trait Implementations§
impl Freeze for ConversionError
impl RefUnwindSafe for ConversionError
impl Send for ConversionError
impl Sync for ConversionError
impl Unpin for ConversionError
impl UnsafeUnpin for ConversionError
impl UnwindSafe for ConversionError
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