pathmod_derive

Crates.iopathmod_derive
lib.rspathmod_derive
version0.1.3
created_at2025-09-02 12:15:13.107809+00
updated_at2025-09-02 13:31:38.919409+00
descriptionDerive macros for pathmod
homepagehttps://github.com/dahankzter/pathmod-rs
repositoryhttps://github.com/dahankzter/pathmod-rs
max_upload_size
id1821052
size30,743
Henrik Johansson (dahankzter)

documentation

https://docs.rs/pathmod_derive

README

pathmod_derive crate

Crates.io docs.rs

Purpose

  • Proc-macro crate providing #[derive(Accessor)] for structs (named and tuple).
  • Generates inherent pub const accessor methods for each field:
    • Named fields: acc_<field>() -> pathmod::Accessor<Self, FieldTy>
    • Tuple fields: acc_<idx>() -> pathmod::Accessor<Self, FieldTy>

Behavior

  • Accessors are built using core::mem::offset_of!, enabling const construction.
  • Composition is available via the runtime type (Accessor) from the core crate.
  • Unit structs and non-struct targets are rejected with clear compile errors.

How to use

  • Most users should depend on pathmod and use pathmod::prelude::*; which re-exports this derive.
  • If depending directly, add to Cargo.toml and import the macro: use pathmod_derive::Accessor; then annotate your types.

Example See top-level README for end-to-end examples. Minimal snippet:

use pathmod::prelude::*;

#[derive(Accessor)]
struct Address { city: String }

fn example() {
    let _acc = Address::acc_city();
}

Limitations and diagnostics

  • Unit structs are not supported.
  • Enums are not supported (future roadmap may add separate enum accessor derive).
  • Visibility follows Rust rules: even though generated methods are pub, private types/field types aren’t accessible from outside their module.
  • UI tests with trybuild cover error messages and generics visibility cases.

MSRV

  • Intended MSRV 1.89+ (for core::mem::offset_of!).

License Dual-licensed under MIT or Apache-2.0.

Commit count: 29

cargo fmt