Skip to content

Commit

Permalink
copy safety assertions from lottie2gif crate to lottie2webp crate
Browse files Browse the repository at this point in the history
  • Loading branch information
msrd0 committed Apr 3, 2022
1 parent 7b6ccdb commit 0822498
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lottie2webp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ pub use rlottie::Animation;
#[macro_use]
mod util;

/// It is very important that [`RGBA8`] and `[u8; 4]` have exactly the same size.
/// This mod does nothing other than fail to compile if that was not the case.
#[allow(dead_code)]
mod rgba_size {
use rgb::RGBA8;
use std::{marker::PhantomData, mem};

#[derive(Default)]
struct AssertSize<const N: usize>(PhantomData<[(); N]>);

impl<const N: usize> AssertSize<N> {
const fn new() -> Self {
Self(PhantomData)
}
}

impl AssertSize<4> {
const fn assert_size_u8_4(self) {}
}

const _: () = {
AssertSize::<{ mem::size_of::<RGBA8>() }>::new().assert_size_u8_4();
AssertSize::<{ mem::size_of::<[u8; 4]>() }>::new().assert_size_u8_4();
};
}

auto_vectorize! {
pub(crate) fn bgra_to_rgba(buf_bgra: &[BGRA8], buf_rgba: &mut [RGBA8]) {
for i in 0..buf_bgra.len() {
Expand Down

0 comments on commit 0822498

Please sign in to comment.