data_record 0.0.0

A procedural macro that generates a trait from a struct, exporting the struct's fields as trait methods and providing a constructor method.
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 24.98 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 317.16 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • BSchneppe

data-record-rs

A procedural macro that auto-generates traits and implementations for your structs, enabling Java record–like behavior in Rust. It creates:

  • A getter trait containing one method per named field.
  • A constructor trait with a canonical constructor (default name new).

This allows you to keep struct fields private while providing read-only access and a standardized way to construct instances.

Features

  • Getter Trait Generation:
    For each named field in your struct, a corresponding method is added to the generated getter trait.

  • Constructor Trait Generation:
    A constructor trait is generated with a method (default: new, customizable) that takes each field as an argument and returns an instance of the struct.

  • Custom Attributes:
    Fine-tune the generated code by applying custom attributes to:

    • The getter trait definition (datarecord_getter_attr)
    • The getter trait implementation (datarecord_getter_impl_attr)
    • The constructor trait definition (datarecord_const_attr)
    • The constructor trait implementation (datarecordgit_const_impl_attr)
    • The constructor method (datarecord_const_impl_method_attr)

Requirements

  • A Rust toolchain that supports procedural macros

Installation

Add the following to your Cargo.toml:

[dependencies]
data_record = "0.1.0"