Trait audio_core::translate::TryTranslate
source · pub trait TryTranslate<T>: Sized {
type Err;
// Required method
fn try_translate(value: T) -> Result<Self, Self::Err>;
}
Expand description
Trait for performing checked translations, where it’s checked if a translation would result in loss of precision.
This will fail if we try to perform a translation between two integer types which are not exactly equivalent.
Examples
use audio::translate::{TryTranslate, IntTranslationError};
assert_eq!(i16::try_translate(-1.0f32), Ok(i16::MIN));
assert_eq!(i16::try_translate(i32::MIN), Ok(i16::MIN));
assert_eq!(i16::try_translate(0x70000000i32), Ok(0x7000i16));
assert!(matches!(i16::try_translate(0x70000001i32), Err(IntTranslationError { .. })));
Required Associated Types§
Required Methods§
sourcefn try_translate(value: T) -> Result<Self, Self::Err>
fn try_translate(value: T) -> Result<Self, Self::Err>
Perform a conversion.
Object Safety§
This trait is not object safe.