impl_osu_accessor

Macro impl_osu_accessor 

Source
macro_rules! impl_osu_accessor {
    ($(fn $name:ident() -> $ret:ty => $call:path),* $(,)?) => { ... };
}
Expand description

Generates OSU memory accessor methods with automatic client dispatching.

This macro eliminates boilerplate code by automatically generating client-specific accessor methods that handle different OSU client types (Stable, Lazer) with consistent error handling.

§Syntax

impl_osu_accessor! {
    fn method_name() -> return_type => implementation_path,
    fn another_method() -> another_type => another_implementation,
}

§Arguments

  • method_name - Name of the generated method (e.g., game_state, score)
  • return_type - Rust type to return (e.g., GameState, i32, String)
  • implementation_path - Path to the actual implementation (e.g., stable::memory::game_state)

§Examples

impl<'a> CommonReader<'a> {
    impl_osu_accessor! {
        fn game_state() -> GameState => stable::memory::game_state,
        fn menu_game_mode() -> GameMode => stable::memory::menu_game_mode,
        fn path_folder() -> PathBuf => stable::memory::path_folder,
    }
}

§Generated Methods

For each definition, generates a method like:

pub fn method_name(&mut self) -> Result<return_type, Error> {
    match self.osu_type {
        OsuClientKind::Stable => implementation_path(self.process, self.state),
        _ => Err(Error::Unsupported("Unsupported osu type for now".to_string())),
    }
}

§Benefits

  • Reduces code duplication - ~1000+ lines eliminated across the project
  • Consistent API - All accessors follow the same pattern
  • Type safety - Compile-time guarantees for return types
  • Future-proof - Easy to add new client types
  • Maintainable - Changes only need to be made in one place

§Errors

Generated methods return Error::Unsupported for client types that don’t have implementations yet (currently only Stable is supported).

§Performance

No runtime overhead - all dispatching is done at compile time.