Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DeepClone for Array<T> #14

Closed
Veykril opened this issue May 12, 2019 · 1 comment
Closed

Implement DeepClone for Array<T> #14

Veykril opened this issue May 12, 2019 · 1 comment
Labels
blocked Cannot be fixed for the time being help wanted Extra attention is needed

Comments

@Veykril
Copy link
Owner

Veykril commented May 12, 2019

For some reason it is not currently possible to implement DeepClone for Array generically either due to a compiler bug or me overlooking something.

blend2d-rs/src/variant.rs

Lines 322 to 332 in f1f116c

// Fails to compile on rust stable but works fine on nightly(E0277). I believe
// this might be related to https://github.com/rust-lang/rust/issues/24159,
// but im unsure as to how one could circumvent it
/*impl<T> DeepClone for Array<T>
where
T: ArrayType,
Array<T>: WrappedBlCore,
<Array<T> as WrappedBlCore>::Core: Copy + 'static,
{
const ASSIGN_DEEP: BlAssignDeep<Self::Core> = ffi::blArrayAssignDeep;
}*/

We can obviously circumvent this by changing the array_type macro to implement DeepClone for each of the types for Array instead. It's not nice but it would solve the problem for the time being

blend2d-rs/src/array.rs

Lines 448 to 504 in f1f116c

macro_rules! impl_array_type {
($( $append:ident, $insert:ident, $replace:ident for $( ($ty:ty = $idx:expr) ),+);*$(;)*) => {
$(
$(
impl ArrayType for $ty {
const IMPL_IDX: usize = $idx as usize;
#[inline]
unsafe fn push(core: &mut ffi::BLArrayCore, item: Self) -> Result<()> {
errcode_to_result(ffi::$append(core, item as _))
}
#[inline]
unsafe fn insert(core: &mut ffi::BLArrayCore, index: usize, item: Self) -> Result<()> {
errcode_to_result(ffi::$insert(core, index, item as _))
}
#[inline]
unsafe fn replace(core: &mut ffi::BLArrayCore, index: usize, item: Self) -> Result<()> {
errcode_to_result(ffi::$replace(core, index, item as _))
}
}
)+
)*
};
($( ( $( $ty:ty ),+ = $idx:expr) );* $(;)*) => {
$(
$(
impl ArrayType for $ty {
const IMPL_IDX: usize = $idx as usize;
}
)+
)*
}
}
impl_array_type! {
blArrayAppendU8, blArrayInsertU8, blArrayInsertU8 for (i8 = ImplType::ArrayI8), (u8 = ImplType::ArrayU8);
blArrayAppendU16, blArrayInsertU16, blArrayInsertU16 for (i16 = ImplType::ArrayI16), (u16 = ImplType::ArrayU16);
blArrayAppendU32, blArrayInsertU32, blArrayInsertU32 for (i32 = ImplType::ArrayI32), (u32 = ImplType::ArrayU32);
blArrayAppendU64, blArrayInsertU64, blArrayInsertU64 for (i64 = ImplType::ArrayI64), (u64 = ImplType::ArrayU64);
blArrayAppendF32, blArrayInsertF32, blArrayInsertF32 for (f32 = ImplType::ArrayF32);
blArrayAppendF64, blArrayInsertF64, blArrayInsertF64 for (f64 = ImplType::ArrayF32);
}
#[cfg(target_pointer_width = "32")]
impl_array_type!(blArrayAppendU32, blArrayInsertU32, blArrayInsertU32 for (isize = ImplType::ArrayI32), (usize = ImplType::ArrayU32));
#[cfg(target_pointer_width = "64")]
impl_array_type!(blArrayAppendU64, blArrayInsertU64, blArrayInsertU64 for (isize = ImplType::ArrayI64), (usize = ImplType::ArrayU64));
mod scope {
use crate::{array::ArrayType, font_defs::*, geometry::*, variant::ImplType, Tag};
impl_array_type! {
(Tag = ImplType::ArrayStruct4);
(PointD, PointI, SizeD, SizeI, FontFeature, FontVariation = ImplType::ArrayStruct8);
(Circle = ImplType::ArrayStruct12);
(BoxD, BoxI, Ellipse, Line, RectD, RectI = ImplType::ArrayStruct16);
(Arc, Chord, Pie, RoundRect, Triangle = ImplType::ArrayStruct24);
}
}
.

@Veykril Veykril added the help wanted Extra attention is needed label May 20, 2019
@Veykril Veykril added the blocked Cannot be fixed for the time being label Jun 24, 2019
@Veykril
Copy link
Owner Author

Veykril commented Jul 19, 2019

seems to work now. Fixed in 4dc1aab.

@Veykril Veykril closed this as completed Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Cannot be fixed for the time being help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant