geo
geo copied to clipboard
Allow an AffineTransform to be constructed from a borrowed array
- [x] I agree to follow the project's code of conduct.
- [x] I added an entry to
CHANGES.mdif knowledge of this change could be valuable to users.
"borrowed array" was formerly "slice", which was wrong!
That's not a slice, is it?
Well this is embarrassing
how about now?
Better. This could probably be A: AsRef<[T; 6]>, but whatever.
Still, as prior art, Ipv4Addr only implements From<[u8; 4]>. And [T; 6] will be Copy, so I'm not sure it's worth adding it.
Better. This could probably be
A: AsRef<[T; 6]>, but whatever.
I actually tried this but got the annoying trait objects must include the dyn keyword error, which also doesn't help since the compiler says dyn AsRef<[T; 6]> + 'static doesn't impl Sized. I gave up at that point, rightly or wrongly.
I meant
impl<T: CoordNum, A: AsRef<[T; 6]>> From<A> for AffineTransform<T> {
fn from(arr: A) -> Self {
let arr = arr.as_ref();
Self::new(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5])
}
}
This would subsume both existing implementations ([T; 6] and (T, T, T, T, T, T)), as well as the one for &[T; 6].
But as I mentioned, I don't think it's necessary. Do you have some example where it helps? Because the following already works today:
fn foo(arr: &[f64; 6]) {
let _tr = AffineTransform::from(*arr);
}
Do you have some example where it helps? Because the following already works today
Only in avoiding the *, which was annoying me…
But maybe your AsRef is the way to go.
Dunno, if From<[u8; 4]> is good enough for the standard library, maybe it's good enough for us? :slightly_smiling_face:.
Fair.
https://github.com/georust/geo/issues/1149