rename into Into

This commit is contained in:
Ponj 2024-07-05 12:47:23 +02:00
parent a1e2111e6d
commit 7b39c8e6dc
Signed by: p6nj
GPG key ID: CEAB625B75A836B2

View file

@ -1,40 +1,40 @@
use dasp_sample::{FromSample, Sample, U24, U48}; use dasp_sample::{FromSample, Sample, U24, U48};
pub trait AsSample<F> pub trait IntoSample<F>
where where
Self: Sized, Self: Sized,
{ {
fn _prepare(self) -> F; fn _prepare(self) -> F;
fn as_sample<S: Sample + FromSample<F>>(self) -> S { fn into_sample<S: Sample + FromSample<F>>(self) -> S {
Sample::from_sample(self._prepare()) Sample::from_sample(self._prepare())
} }
} }
impl AsSample<u8> for u8 { impl IntoSample<u8> for u8 {
fn _prepare(self) -> u8 { fn _prepare(self) -> u8 {
self self
} }
} }
impl AsSample<u16> for [u8; 2] { impl IntoSample<u16> for [u8; 2] {
fn _prepare(self) -> u16 { fn _prepare(self) -> u16 {
((self[0]._prepare() as u16) << 8) | self[1] as u16 ((self[0]._prepare() as u16) << 8) | self[1] as u16
} }
} }
impl AsSample<U24> for [u8; 3] { impl IntoSample<U24> for [u8; 3] {
fn _prepare(self) -> U24 { fn _prepare(self) -> U24 {
(U24::from([self[0], self[1]]._prepare()) << 8.into()) | U24::from(self[2]) (U24::from([self[0], self[1]]._prepare()) << 8.into()) | U24::from(self[2])
} }
} }
impl AsSample<u32> for [u8; 4] { impl IntoSample<u32> for [u8; 4] {
fn _prepare(self) -> u32 { fn _prepare(self) -> u32 {
(([self[0], self[1], self[2]]._prepare().inner() as u32) << 8) | self[3] as u32 (([self[0], self[1], self[2]]._prepare().inner() as u32) << 8) | self[3] as u32
} }
} }
impl AsSample<U48> for [u8; 6] { impl IntoSample<U48> for [u8; 6] {
fn _prepare(self) -> U48 { fn _prepare(self) -> U48 {
((U48::from([self[0], self[1], self[2], self[3]]._prepare()) << 16u8.into()) ((U48::from([self[0], self[1], self[2], self[3]]._prepare()) << 16u8.into())
| (U48::from(self[4]) << 8u8.into())) | (U48::from(self[4]) << 8u8.into()))