lib_utils
This is library with handy functions used across my projects
Features
There are some features you can enable:
- b32 - This is a base32 encoding/decoding library
- b58 - This is a base58 encoding/decoding library
- b64 - This is a base64 encoding/decoding library
- cuuid - This is a uuid library that encodes/decodes uuid to/from BaseX string, requires also one of the following features: b32, b58, b64
- envs - This is a library that loads environment variables. With it you can easily load configs
- time - This is a library that provides UTC time functions
By default enabled features are: envs
Usage
Add this into your Cargo.toml
[]
= { = "0.2.0", = ["envs", "time", "b32", "b58", "b64", "cuuid"] }
BaseX encoding-decoding
All schemes shares the same interface, so you just enable requested BaseX as feature, for example b64
After this all you need is use it like this:
use b64u; // or b64 for not URL-safe
let b64_str = encode;
let decoded_bytes = decode?;
let decoded_str = decode_to_string?;
Uuid BaseX encofing-decoding
In order to use it, you need to add one of the baseX features and cuuid feature as well
From existing Uuid
use CUuid;
use Uuid;
// Create id
let id_v4 = new_v4;
let id_v7 = now_v7;
// Encode
let encoded: String = B64.from;
let encoded: String = B64.from;
Create and encode
use CUuid;
use Uuid;
// Encode
let encoded: String = B64.new_v4;
let encoded: String = B64.now_v7;
Decode
use CUuid;
use Uuid;
let encoded: String = B64.new_v4;
let id: Uuid = B64.decode;
Environment variables reading
For development you can create ./.cargo/config.toml file and set your variables there
# config.toml
[]
# For single value
= "my value"
# For array
= "ENV1:VALUE1,ENV2:VALUE2"
Single value loading
use envs;
// If you just need to read string, use this:
let value: String = get?;
// You also can parse value from string. Type must implement `FromStr` trait
let value: i32 = get_parse?;
// If your value is BaseX encoded string, you can read it as
// -- BaseX decoded string bytes. Add feature `b64` to enable method
let value: = get_b64u_as_u8s?;
// -- BaseX decoded string. Add feature `b64` to enable method
let value: String = get_b64u_as_s?;
Array of values loading
use envs;
// If you need to load keys from configuration, or just an array of values, use this
let keys: = get_keys?;
// There are also a way to parse it as well. Type must implement `FromStr` trait
let keys: = get_keys_parse?;
// If your keys encoded as BaseX, you can read it as
// -- BaseX decoded string bytes. Add feature `b64` to enable method
let keys: = get_keys_b64u_as_u8s?;
// -- BaseX decoded string. Add feature `b64` to enable method
let keys: = get_keys_b64u_as_s?;
Examples
There are some examples in examples folder.
Some of them requires features, so run them with:
Contributing
Contributions are welcome! If you have suggestions for improvements or new features, feel free to open an issue or submit a pull request. I wrote this library for my own use, so it may not fit everyone's needs, but your input is appreciated!
License
This project is licensed under the MIT License - see the LICENSE file for details.