#env-var #array #variables #constant #encoded-string #string-literal #hex

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

#1307 in Procedural macros

Download history 23/week @ 2024-03-09 40/week @ 2024-03-16 174/week @ 2024-03-23 52/week @ 2024-03-30 53/week @ 2024-04-06 113/week @ 2024-04-13 14/week @ 2024-04-20 74/week @ 2024-05-04 2/week @ 2024-05-11 26/week @ 2024-05-18 21/week @ 2024-05-25 35/week @ 2024-06-01 18/week @ 2024-06-08 2/week @ 2024-06-15 2/week @ 2024-06-22

64 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
~46K SLoC