I'm trying to create a Rust vector type that only needs to work on WASM, but that I want to map to the WASM v128
type.
I can accomplish a working version by creating a type like this:
use core::arch::wasm32;
#[repr(transparent)]
pub struct Vec4(wasm32::v128);
impl Vec4 {
// impl vector functions
}
But I want to, for ergonomics sake be able to access individual fields in the type by just doing my_var.x
, my_var.y
, etc.
I could easily create functions such as get_x()
and set_x()
, but that is much more typing that just x
.
On nightly you can use #[repr(simd)]
, it looks like, and do this:
#[repr(simd)]
pub struct Vec4 {
x: f32,
y: f32,
z: f32,
w: f32,
}
I'm really trying to avoid having to use nightly, though. Are there any hacks I can use to somehow make this work?
I'm fairly certain there's no way in Rust to make field access resolve to a function right? Like automatically converting my_var.x = 3
to my_var.set_x(3)
?