#env-var #array #constant #string #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

#1650 in Procedural macros

Download history 2/week @ 2023-12-18 2/week @ 2023-12-25 21/week @ 2024-01-08 26/week @ 2024-01-15 60/week @ 2024-01-22 182/week @ 2024-01-29 114/week @ 2024-02-26 291/week @ 2024-03-04 15/week @ 2024-03-11 42/week @ 2024-03-18 180/week @ 2024-03-25 129/week @ 2024-04-01

372 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
~43K SLoC