| Crates.io | affn-derive |
| lib.rs | affn-derive |
| version | 0.1.0 |
| created_at | 2025-12-21 18:23:08.72726+00 |
| updated_at | 2025-12-21 18:23:08.72726+00 |
| description | Derive macros for affn: ReferenceFrame and ReferenceCenter |
| homepage | |
| repository | https://github.com/Siderust/affn |
| max_upload_size | |
| id | 1998421 |
| size | 14,904 |
Procedural macros for the affn crate, providing convenient derive macros for ReferenceFrame and ReferenceCenter traits.
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.
These derives are re-exported from the affn crate, so you typically don't need to depend on this crate directly:
use affn::prelude::*;
#[derive(Debug, Copy, Clone, ReferenceFrame)]
struct MyFrame;
#[derive(Debug, Copy, Clone, ReferenceCenter)]
struct MyCenter;
assert_eq!(MyFrame::frame_name(), "MyFrame");
assert_eq!(MyCenter::center_name(), "MyCenter");
#[derive(ReferenceFrame)]Implements the ReferenceFrame trait with the struct name as the frame name.
Optional attributes:
#[frame(name = "CustomName")] - Override the frame nameExample:
use affn::prelude::*;
#[derive(Debug, Copy, Clone, ReferenceFrame)]
#[frame(name = "International Celestial Reference System")]
struct ICRS;
assert_eq!(ICRS::frame_name(), "International Celestial Reference System");
#[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 custom Params type (must implement Clone + Debug + Default + PartialEq)#[center(affine = false)] - Skip implementing the AffineCenter marker traitExample (simple center):
use affn::prelude::*;
#[derive(Debug, Copy, Clone, ReferenceCenter)]
struct Heliocentric;
assert_eq!(Heliocentric::center_name(), "Heliocentric");
Example (parameterized center):
use affn::prelude::*;
#[derive(Clone, Debug, Default, PartialEq)]
struct ObserverLocation {
latitude: f64,
longitude: f64,
altitude: f64,
}
#[derive(Debug, Copy, Clone, ReferenceCenter)]
#[center(params = ObserverLocation)]
struct Topocentric;
The types deriving these traits must also derive or implement:
DebugCopyCloneFor parameterized centers, the Params type must implement:
CloneDebugDefaultPartialEqIf you're migrating from the old new_frame! and new_center! macros:
Old:
affn::new_frame!(ICRS);
affn::new_center!(Heliocentric);
New:
use affn::prelude::*;
#[derive(Debug, Copy, Clone, ReferenceFrame)]
struct ICRS;
#[derive(Debug, Copy, Clone, ReferenceCenter)]
struct Heliocentric;
The derive macros provide:
AGPL-3.0-only