Bin to Hex


Rust adjustments for the left side bar tool "Bin to Hex".


What adjustments do I need to make in Rust?

In summary, here are the steps you need to take to create the API function.

Cargo.toml

There is no need to add any crates.

api.rs - Used Paths

Add this path:

use std::u32;

api.rs - Function bin_to_hex()

#[allow(dead_code)]
pub fn bin_to_hex(val: String, len: usize) -> String {
    let n: u32 = u32::from_str_radix(&val, 2).unwrap();
    format!("{:01$x}", n, len * 2)
}

Checks using cargo build


All checks (-> except iOS Simulator) should work without any issue. Please also refer to the explanations of Example 3 and the corresponding video (2023-09-03: ToDo).


To examine the various targets, you should navigate from playground_app root directory to the rust directory:

cd rust

Then, within the rust directory, excute the following commands.

Android

If you haven't already, install the cargo-ndk command using:

cargo install cargo-ndk

I only check the ABI arm64-v8a.

a) If you've had NO problems with the 3rd party library libsodium, use the command:

cargo ndk -t arm64-v8a build

b) If you've HAD problems with the 3rd party library libsodium, use the command:

SODIUM_LIB_DIR="/path/to/libsodium" SODIUM_SHARED=1 cargo ndk -t arm64-v8a build

e.g.

SODIUM_LIB_DIR="/Users/yourname/playground_app/android/app/src/main/jniLibs/arm64-v8a" SODIUM_SHARED=1 cargo ndk -t arm64-v8a build

-> Why do you need SODIUM_LIB_DIR and SODIUM_SHARED here?

macOS

cargo build --target aarch64-apple-darwin

iOS Simulator

This check will fail, please refer to the explanations of Example 3 (Libsodium).

cargo build --target aarch64-apple-ios-sim

iOS Device

cargo build --target aarch64-apple-ios