| Crates.io | uniform-array-derive |
| lib.rs | uniform-array-derive |
| version | 0.1.0 |
| created_at | 2024-07-03 15:42:20.765841+00 |
| updated_at | 2024-07-03 15:42:20.765841+00 |
| description | A derive macro for turning uniform types into slices |
| homepage | https://github.com/sunsided/uniform-array-derive |
| repository | https://github.com/sunsided/uniform-array-derive |
| max_upload_size | |
| id | 1290630 |
| size | 14,229 |
Derive array-like behavior for your structs of uniform types.
This will derive AsRef<[T]>, AsMut<[T]>, Deref<Target = [T]>, DerefMut, Index<Target = T>andIndexMutfor your homogeneous structs field typeT. Since the generated code is unsafe, it is feature gated behind a #[cfg(feature = "unsafe")]` by default.
#[derive(UniformArray)]
pub struct Vector3 {
pub x: f32,
pub y: f32,
pub z: f32,
}
#[derive(UniformArray)]
pub struct Coordinate(u32, u32);
If you need to rename the feature gate, you can do that as well:
/// Use a custom feature gate instead of "unsafe".
#[derive(UniformArray)]
#[uniform_array(safety_gate = "super_unsafe")]
pub struct Quaternion<T>
where
T: Sized,
{
pub a: T,
pub b: T,
pub c: T,
pub d: T,
}
If you only need to ensure that all your fields have the same type, consider the ensure-uniform-type crate instead.