affn-derive

Crates.ioaffn-derive
lib.rsaffn-derive
version0.1.0
created_at2025-12-21 18:23:08.72726+00
updated_at2025-12-21 18:23:08.72726+00
descriptionDerive macros for affn: ReferenceFrame and ReferenceCenter
homepage
repositoryhttps://github.com/Siderust/affn
max_upload_size
id1998421
size14,904
Vallés Puig, Ramon (VPRamon)

documentation

README

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 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");

Attributes

#[derive(ReferenceFrame)]

Implements the ReferenceFrame trait with the struct name as the frame name.

Optional attributes:

  • #[frame(name = "CustomName")] - Override the frame name

Example:

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 trait

Example (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;

Requirements

The types deriving these traits must also derive or implement:

  • Debug
  • Copy
  • Clone

For parameterized centers, the Params type must implement:

  • Clone
  • Debug
  • Default
  • PartialEq

Migration from Declarative Macros

If 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:

  • 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

Commit count: 0

cargo fmt