affn-derive
Procedural macros for the affn crate, providing convenient derive macros for ReferenceFrame and ReferenceCenter traits.
Overview
This crate provides derive macros that automatically implement the ReferenceFrame and ReferenceCenter traits from the affn crate, eliminating boilerplate and providing better IDE support than declarative macros.
Usage
These derives are re-exported from the affn crate, so you typically don't need to depend on this crate directly:
use *;
;
;
assert_eq!;
assert_eq!;
Attributes
#[derive(ReferenceFrame)]
Implements the ReferenceFrame trait with the struct name as the frame name.
Optional attributes:
#[frame(name = "CustomName")]- Override the frame name#[frame(polar = "dec", azimuth = "ra")]- ImplementSphericalNamingwith custom axis labels#[frame(distance = "altitude")]- Override the spherical distance label#[frame(inherent)]- Generate frame-specific inherent constructors/getters on spherical types#[frame(ellipsoid = "Wgs84")]- ImplementHasEllipsoidfor ellipsoid-aware geodetic conversions
Example:
use *;
;
assert_eq!;
#[derive(ReferenceCenter)]
Implements the ReferenceCenter trait with Params = () by default. Also automatically implements the AffineCenter marker trait.
Optional attributes:
#[center(name = "CustomName")]- Override the center name#[center(params = MyType)]- Specify a customParamstype (must implementClone + Debug + Default + PartialEq)#[center(affine = false)]- Skip implementing theAffineCentermarker trait
Example (simple center):
use *;
;
assert_eq!;
Example (parameterized center):
use *;
;
Requirements
The types deriving these traits must also derive or implement:
DebugCopyClone
For parameterized centers, the Params type must implement:
CloneDebugDefaultPartialEq
Migration from Declarative Macros
If you're migrating from the old new_frame! and new_center! macros:
Old:
new_frame!;
new_center!;
New:
use *;
;
;
The derive macros provide:
- Better IDE support (autocomplete, go-to-definition, etc.)
- More flexible customization via attributes
- Clearer error messages
- Standard Rust derive syntax
License
AGPL-3.0-only