macro_rules! cast_int {
($ctx:expr, $field:expr, $len:expr) => { ... };
($field:expr, $len:expr) => { ... };
}
Expand description
Safely casts an integer to a different integer type.
This macro attempts to convert an integer value to a different integer type, returning an error if the conversion fails due to out-of-range issues.
§Arguments
ctx
- The context for the error message (optional)field
- The name of the field being castlen
- The integer value to cast
§Examples
use ironrdp_core::cast_int;
fn process_value(value: u64) -> Result<i32, Error> {
let casted_value: i32 = cast_int!("input value", value)?;
Ok(casted_value)
}
§Note
If the context is not provided, it will use the current function name.