Get
The Get derive macro generates getter methods for struct fields. Annotate fields with #[moxy(get)] to opt in — unannotated fields get no getter.
Getters return through Deref::Target, so String fields return &str, Vec<T> returns &[T], etc. Use copy for primitives and clone for types like Arc<T>.
Note
Getters return
&Deref::Target, not&T. This is more ergonomic for common types (String→&str,Vec<T>→&[T]), but for types without a naturalDereftarget, useget(copy)orget(clone)to get an owned value instead.
Basic Usage
use moxy::Get;
#[derive(Get)]
struct User {
#[moxy(get)]
name: String,
#[moxy(get)]
email: String,
password_hash: String,
}
let user = User {
name: "alice".into(),
email: "a@b.com".into(),
password_hash: "hash".into(),
};
assert_eq!(user.name(), "alice"); // fn name(&self) -> &str
assert_eq!(user.email(), "a@b.com"); // fn email(&self) -> &str
// user.password_hash() — no annotation, no getter
What’s Next
- Modifiers — copy, clone, and mutable variants
- Option Fields — automatic
Option<&str>viaas_deref() - Callbacks — side effects with
on = expr