diff --git a/src/lib.rs b/src/lib.rs index a0d1e7c..33a27f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,7 +86,7 @@ confusable_idents, internal_features )] -use std::{hint::assert_unchecked, num::NonZeroU32, ops::Range}; +use std::{hint::assert_unchecked, intrinsics::transmute_unchecked, num::NonZeroU32, ops::Range}; mod affine; #[cfg(feature = "blur")] @@ -448,6 +448,18 @@ impl Image { self.buffer().as_ref().len() } + /// Transforms the N + /// + /// # Safety + /// + /// i think you can see why this is a problem. + /// + /// # WHY??? + /// + /// sometimes rust is silly with generics + unsafe fn trans(self) -> Image { + unsafe { transmute_unchecked(self) } + } /// # Safety /// /// the output index is not guaranteed to be in bounds diff --git a/src/term/bloc.rs b/src/term/bloc.rs index 7bafd78..58c8655 100644 --- a/src/term/bloc.rs +++ b/src/term/bloc.rs @@ -50,16 +50,17 @@ where let (w, h) = fit((self.width(), self.height())); macro_rules! n { ($n:literal) => { - transmute::, $n>, Image, N>>( - transmute::, Image<&[u8], $n>>(self.as_ref()) - .scale::(w, h), - ) + self.as_ref() + .trans::<$n>() + .scale::(w, h) + .trans::() }; (o $n:literal) => { - transmute::, 1>, Image, N>>( - transmute::, N>, Image, 1>>(self.as_ref().to_owned()) - .scale::(w, h), - ) + self.as_ref() + .to_owned() + .trans::<1>() + .scale::(w, h) + .trans::() }; } // SAFETY: #[allow(clippy::undocumented_unsafe_blocks)] diff --git a/src/term/iterm2.rs b/src/term/iterm2.rs index 9a737a7..8ec5f42 100644 --- a/src/term/iterm2.rs +++ b/src/term/iterm2.rs @@ -42,7 +42,7 @@ where ($n:literal) => { WritePng::write( // SAFETY: ... i renounce traits - &unsafe { transmute::, Image<&[u8], $n>>(self.as_ref()) }, + &unsafe { self.as_ref().trans::<$n>() }, &mut d, ) .unwrap() diff --git a/src/term/kitty.rs b/src/term/kitty.rs index b1db99a..dd13cb7 100644 --- a/src/term/kitty.rs +++ b/src/term/kitty.rs @@ -45,7 +45,7 @@ impl, const N: usize> Kitty { Cow::Owned( , 3>>::from({ // SAFETY: ... - unsafe { transmute::, Image<&[u8], $n>>(self.as_ref()) } + unsafe { self.as_ref().trans::<$n>() } }) .take_buffer() .to_vec(),