get_variable_size_field_optional

Function get_variable_size_field_optional 

Source
pub fn get_variable_size_field_optional<const N: usize, F>(
    field_code: i32,
    host_fn: F,
) -> Result<Option<([u8; N], usize)>>
where F: FnOnce(i32, *mut u8, usize) -> i32,
Expand description

Optional variant of get_variable_size_field.

Returns None if the field is not found, otherwise behaves identically to the required variant.

§Type Parameters

  • N - The maximum size of the buffer (compile-time constant)
  • F - The type of the host function closure

§Arguments

  • field_code - The field code identifying which field to retrieve
  • host_fn - A closure that calls the appropriate host function

§Returns

Returns Result<Option<([u8; N], usize)>> where:

  • Ok(Some((buffer, len))) - If the field is present
  • Ok(None) - If the field is not found
  • Err(Error) - If there’s an error retrieving the field

§Example

let result = get_variable_size_field_optional::<48>(
    field_code,
    |fc, buf, size| unsafe { get_current_ledger_obj_field(fc, buf, size) },
)?;