Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Forward

#[derive(Forward)] generates methods that delegate to inner fields (structs) or variant payloads (enums). You declare the method signatures to forward using #[moxy(forward(fn ...))].

Since proc macros cannot see type information, you explicitly declare which methods to forward.

use moxy::Forward;

#[derive(Forward)]
struct Cache {
    #[moxy(forward(
        fn len(&self) -> usize,
        fn is_empty(&self) -> bool,
    ))]
    store: Vec<String>,
}

let cache = Cache { store: vec!["a".into(), "b".into()] };
assert_eq!(cache.len(), 2);
assert!(!cache.is_empty());

See Also

  • Structs — forwarding to struct fields
  • Enums — forwarding across enum variants