Skip to main content

io_define_write

Macro io_define_write 

Source
macro_rules! io_define_write {
    (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 writing to an I/O backend.

This macro reduces boilerplate by automatically generating either compile-time bounds-checked (infallible) or runtime bounds-checked (fallible) write methods. It abstracts the address calculation and bounds checking, and delegates the actual I/O write 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 (). fallible performs runtime checks against maxsize() and returns a Result.
  • $(#[$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., write32, try_write8).
  • $call_macro:ident - The backend-specific helper macro used to emit the actual I/O call (e.g., call_mmio_write).
  • $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 written (e.g., u8, u32). Note the use of <- before the type to denote a write operation.