#env-var #array #constant #string #encoded-string #literals #string-literal

macro env_to_array

Auxiliary crate for collecting arrays in different encodings from string constant & environment variables

5 unstable releases

0.3.1 Jun 6, 2023
0.3.0 Jun 6, 2023
0.1.2 Jun 6, 2023
0.1.1 Feb 16, 2023
0.0.0 Nov 14, 2022

#34 in #encoded-string

Download history 54/week @ 2024-07-28 3/week @ 2024-08-04 47/week @ 2024-08-18 2/week @ 2024-08-25 323/week @ 2024-09-01 70/week @ 2024-09-08 39/week @ 2024-09-22 92/week @ 2024-10-06 28/week @ 2024-10-13 56/week @ 2024-10-20 53/week @ 2024-10-27 93/week @ 2024-11-03 34/week @ 2024-11-10

236 downloads per month
Used in debridge-solana-sdk

MIT license

11KB
117 lines

Env To Array

This crate allows you to create constant arrays from encoded string literals as well as take them directly from the env variable.

Install

cargo add env-to-array

Usage

Get from env variable string, decode it from format and put integer array as result

base58

The bs58 feature should be enabled (enabled by default)

/// Get array from env variable encoded by base58
const BS58_ENV_ID: [u8; 17] = env_to_array::bs58_env_to_array!("_ENV_TO_ARRAY_BS58");

/// Get array from constant encoded by base58
const BS58_ID: [u8; 17] = env_to_array::bs58_to_array!("dwVAPpaonY26V6JH17ToUQ");

base64

The bs64 feature should be enabled (enabled by default)

/// Get array from env variable encoded by base64
const BS64_ENV_ID: [u8; 32] = env_to_array::bs64_env_to_array!("_ENV_TO_ARRAY_BS64");

/// Get array from constant encoded by base64
const BS64_ID: [u8; 32] = env_to_array::bs64_to_array!("W7MmhbfqLQc4LbN0TUPfiflxSO6uVZ7E0NH+76LueJ0=");

hex

The hex feature should be enabled (enabled by default)

/// Get array from env variable encoded by hex
const HEX_ENV_ID: [u64; 64] = env_to_array::hex_env_to_array!("_ENV_TO_ARRAY_HEX");

/// Get array from constant encoded by hex
const HEX_ID: [u64; 64] = env_to_array::hex_to_array!("5bb32685b7e5bb32685b7ea2d07382db3744d43df89f97148eeae559ec4d0d1feefa2ee789da2d07382db3744d43df89f97148eeae559ec4d0d1feefa2ee789d");

base32

The bs32 feature should be enabled (enabled by default)

/// Get array from env variable encoded by base58
const BS32_ENV_ID: [u8; 5] = env_to_array::bs32_env_to_array!("_ENV_TO_ARRAY_BS32");

/// Get array from constant encoded by base58
const BS32_ID: [u8; 5] = env_to_array::bs32_to_array!("Z0Z0Z0Z0");

base85

The bs85 feature should be enabled (enabled by default)

/// Get array from env variable encoded by base58
const BS85_ENV_ID: [u8; 5] = env_to_array::bs32_env_to_array!("_ENV_TO_ARRAY_BS85");

/// Get array from constant encoded by base58
const BS85_ID: [u8; 5] = env_to_array::bs32_to_array!("VPRomVPRn");

Dependencies

~2MB
~48K SLoC