Crates.io | data_record |
lib.rs | data_record |
version | |
source | src |
created_at | 2025-02-01 15:09:26.540349 |
updated_at | 2025-02-01 15:09:26.540349 |
description | A procedural macro that generates a trait from a struct, exporting the struct's fields as trait methods and providing a constructor method. |
homepage | |
repository | |
max_upload_size | |
id | 1538500 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A procedural macro that auto-generates traits and implementations for your structs, enabling Java record–like behavior in Rust. It creates:
new
).This allows you to keep struct fields private while providing read-only access and a standardized way to construct instances.
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
)
Add the following to your Cargo.toml
:
[dependencies]
data_record = "0.1.0"