kvark / mint

Math Interoperability Types
MIT License
256 stars 20 forks source link

Publish a new Version #67

Closed sanbox-irl closed 3 years ago

sanbox-irl commented 3 years ago

Hiya!

The recent changes in the last commit allowed for some type simplification as a library maker.

// this COMPILES ON MASTER right now, but NOT on `0.5.6`.
fn test<T>(input: &mut T)
where
    T: Copy + Into<MintVec3> + From<MintVec3>,
{
    let as_mint = (*input).into();
    let mut as_vec3: [f32; 3] = as_mint.into();

    let changed = mutate_vec3(&mut as_vec3);

    if changed {
        let as_mint: MintVec3 = as_vec3.into();
        *input = as_mint.into();
    }
}

// this compiles on both, but is ugly
fn test3<T>(input: &mut T)
where
    T: Copy + Into<MintVec3>,
    MintVec3: Into<T> + Into<[f32; 3]>,
{
    let as_mint = (*input).into();
    let mut as_vec3: [f32; 3] = as_mint.into();

    let changed = mutate_vec3(&mut as_vec3);

    if changed {
        let as_mint: MintVec3 = as_vec3.into();
        *input = as_mint.into();
    }
}

fn mutate_vec3(input: &mut [f32; 3]) -> bool {
    todo!()
}
kvark commented 3 years ago

Done!