kvark/mint

Switch to const generics

porky11 opened this issue · 5 comments

I think, it should be possible to represent all types of this library as const generics already.
This would allow vectors, points and matrices (etc.) of higher dimensions as well.

The currently existing types can still exist by using type aliases, so this isn't even a breaking change.

kvark commented

Sounds very nice! Would you want to prototype a PR?

kvark commented

One problem I foresee is that it will bump the MSRV quite a bit, but eventually this is going to be OK.

Sounds very nice! Would you want to prototype a PR?

I'll try it.

One problem I foresee is that it will bump the MSRV quite a bit, but eventually this is going to be OK.

I never heard about MSRV, but I guess you're talking about the minimal compiler version.
Someone, who is able to update a library, should also be able to update the compiler.
So it's kind of a breaking change? Or is it possible to ensure, if the compiler is too old, it does not try to use the latest version of a library by default, but the latest compatible one?

Ok, I just realized it would be a breaking change anyway.
Currently, the fields are public and named like this:

pub struct Vector2<T> {
    pub x: T,
    pub y: T,
}

I would have to use a vector instead like this:

pub struct Vector<T, const D: usize>([T; D]);
pub type Vector2<T> = Vector<T, D>;

Not sure, if being generic is worth a less user friendly API.
But the code is pretty clean and minimal, so it shouldn't be too difficult to implement.

Not sure, if being generic is worth a less user friendly API.

I think being convenient for direct manipulation by users isn't quite the goal of mint, so this might not be a big deal.