thread_extract_param

Macro thread_extract_param 

Source
macro_rules! thread_extract_param {
    ($param:expr, $t:ty) => { ... };
}
Expand description

Extracts a typed parameter from an optional boxed Any reference.

This macro is used in thread/task entry points to safely extract and downcast parameters passed to the thread. It handles both the Option unwrapping and the type downcast, returning appropriate errors if either operation fails.

§Parameters

  • $param - An Option<Box<dyn Any>> containing the parameter
  • $t - The type to downcast the parameter to

§Returns

  • A reference to the downcasted value of type $t
  • Err(Error::NullPtr) - If the parameter is None
  • Err(Error::InvalidType) - If the downcast fails

§Examples

use osal_rs::thread_extract_param;
use osal_rs::utils::Result;
use core::any::Any;
 
struct TaskConfig {
    priority: u8,
    stack_size: usize,
}
 
fn task_entry(param: Option<Box<dyn Any>>) -> Result<()> {
    let config = thread_extract_param!(param, TaskConfig);
     
    println!("Priority: {}", config.priority);
    println!("Stack: {}", config.stack_size);
     
    Ok(())
}