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

Allow an AffineTransform to be constructed from a borrowed array #1105

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

urschrei
Copy link
Member

@urschrei urschrei commented Nov 3, 2023

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

"borrowed array" was formerly "slice", which was wrong!

@lnicola
Copy link
Member

lnicola commented Nov 3, 2023

That's not a slice, is it?

@urschrei
Copy link
Member Author

urschrei commented Nov 3, 2023

Well this is embarrassing

@urschrei urschrei changed the title Allow an AffineTransform to be constructed from a slice Allow an AffineTransform to be constructed from a borrowed array Nov 3, 2023
@urschrei
Copy link
Member Author

urschrei commented Nov 3, 2023

how about now?

@lnicola
Copy link
Member

lnicola commented Nov 3, 2023

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.

@urschrei
Copy link
Member Author

urschrei commented Nov 3, 2023

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.

@lnicola
Copy link
Member

lnicola commented Nov 3, 2023

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);
}

@urschrei
Copy link
Member Author

urschrei commented Nov 3, 2023

Do you have some example where it helps? Because the following already works today

Only in avoiding the *, which was annoying me…

@urschrei
Copy link
Member Author

urschrei commented Nov 3, 2023

But maybe your AsRef is the way to go.

@lnicola
Copy link
Member

lnicola commented Nov 3, 2023

Dunno, if From<[u8; 4]> is good enough for the standard library, maybe it's good enough for us? 🙂.

@urschrei
Copy link
Member Author

urschrei commented Nov 3, 2023

Fair.

@frewsxcv
Copy link
Member

#1149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants