Skip to content

Commit

Permalink
Using transmute is not required when defining callbacks used by C API
Browse files Browse the repository at this point in the history
  • Loading branch information
yogh333 committed Jun 25, 2024
1 parent c29f244 commit 30f7fed
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ledger_device_sdk/src/nbgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ pub extern "C" fn io_recv_and_process_event() -> bool {
}

/// Callback triggered by the NBGL API when a setting switch is toggled.
unsafe fn settings_callback(token: ::core::ffi::c_int, _index: u8, _page: ::core::ffi::c_int) {
unsafe extern "C" fn settings_callback(
token: ::core::ffi::c_int,
_index: u8,
_page: ::core::ffi::c_int,
) {
let idx = token - FIRST_USER_TOKEN as i32;
if idx < 0 || idx >= SETTINGS_SIZE as i32 {
panic!("Invalid token.");
Expand Down Expand Up @@ -237,10 +241,7 @@ impl<'a> NbglHomeAndSettings<'a> {
nbSwitches: self.nb_settings,
},
},
contentActionCallback: transmute(
(|token, index, page| settings_callback(token, index, page))
as fn(::core::ffi::c_int, u8, ::core::ffi::c_int),
),
contentActionCallback: Some(settings_callback),
type_: SWITCHES_LIST,
};

Expand Down

0 comments on commit 30f7fed

Please sign in to comment.