-
Notifications
You must be signed in to change notification settings - Fork 155
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
cast to lower-level buffer ref #497
Comments
These methods are already there, see https://docs.rs/cgmath/0.17.0/cgmath/struct.Vector4.html#impl-AsRef%3C%5BS%3B%204%5D%3E |
Yes, to cast |
I think solving this is out of scope for cgmath. The desire to reinterpret elements of collections is common (rust-lang/rfcs#2756) but, as you can see from the pr, there are quite some things to consider. That being said, I would not be surprised if there are crates out there that provide these conversions and traits which cgmath could implement. If you find any of those we could look at it. |
The |
@vjackson725 so you are suggesting |
Did the optional bytemuck support ever land to cgmath? I have tricky situation where my struct is used in many places and is defined as such : #[derive(Clone)]
pub struct Triangle {
pub vertices: [Vector3<Real>; 3],
pub normal: [Vector3<Real>; 3],
pub uv: [Vector2<Real>; 3],
} If I try to add the typical bytemuck derive options here ( |
Yes, cgmath now uses bytemuck optionally. Enable the feature "bytemuck" to use it. This looks to have been added in #541. |
I'm looking to use this feature, but the referenced PR doesn't actually add bytemuck as an available feature in cargo.toml? |
@matt328 Me too. |
It's not part of an official release yet. You'll need to pull from the
|
Would it be possible to add a trait to downcast
&[Vector<T>]
to&[[T; N]]
and&[T]
?I work with buffers of vectors, and I need to pass them to other libraries, that are using
&[T]
for compatibility. For now I only copy it element by element, but I think that copy could be avoided with a simple reference cast.For example, something like that
and maybe also the inverse
I think it's possible because the
Vector
struct is markedrepr(C)
and its fields are all of the same type (so there is no alignment concerns). Plus all slices are contiguous data storagesThis kind of cast would get it much more simple to get from a buffer type to an other. (slices, vec, ndarray, with grouped components or not).
The text was updated successfully, but these errors were encountered: