Skip to main content

io_define_read

Macro io_define_read 

Source
macro_rules! io_define_read {
    (infallible, $(#[$attr:meta])* $vis:vis $name:ident, $call_macro:ident($c_fn:ident) ->
     $type_name:ty) => { ... };
    (fallible, $(#[$attr:meta])* $vis:vis $try_name:ident, $call_macro:ident($c_fn:ident) ->
     $type_name:ty) => { ... };
}
Expand description

Generates an accessor method for reading from an I/O backend.

This macro reduces boilerplate by automatically generating either compile-time bounds-checked (infallible) or runtime bounds-checked (fallible) read methods. It abstracts the address calculation and bounds checking, and delegates the actual I/O read operation to a specified helper macro, making it generic over different I/O backends.

ยงParameters

  • infallible / fallible - Determines the bounds-checking strategy. infallible relies on IoKnownSize for compile-time checks and returns the value directly. fallible performs runtime checks against maxsize() and returns a Result<T>.
  • $(#[$attr:meta])* - Optional attributes to apply to the generated method (e.g., #[cfg(CONFIG_64BIT)] or inline directives).
  • $vis:vis - The visibility of the generated method (e.g., pub).
  • $name:ident / $try_name:ident - The name of the generated method (e.g., read32, try_read8).
  • $call_macro:ident - The backend-specific helper macro used to emit the actual I/O call (e.g., call_mmio_read).
  • $c_fn:ident - The backend-specific C function or identifier to be passed into the $call_macro.
  • $type_name:ty - The Rust type of the value being read (e.g., u8, u32).