| Crates.io | grapple_utils |
| lib.rs | grapple_utils |
| version | 0.2.0 |
| created_at | 2025-05-24 18:56:07.871864+00 |
| updated_at | 2025-06-26 15:52:53.551446+00 |
| description | A collection of utilities for Rust development. |
| homepage | |
| repository | https://github.com/grapple228/rust_grapple_utils.git |
| max_upload_size | |
| id | 1687687 |
| size | 69,720 |
This is library with handy functions used across my projects
There are some features you can enable:
By default enabled features are: envs
Add this into your Cargo.toml
[dependencies]
grapple_utils = { version = "0.2.0", features = ["envs", "time", "b32", "b58", "b64", "cuuid"] }
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 grapple_utils::b64u; // or b64 for not URL-safe
let b64_str = b64u::encode("my string");
let decoded_bytes = b64u::decode(&b64_str)?;
let decoded_str = b64u::decode_to_string(&b64_str)?;
In order to use it, you need to add one of the baseX features and cuuid feature as well
From existing Uuid
use grapple_utils::cuuid::CUuid;
use uuid::Uuid;
// Create id
let id_v4 = Uuid::new_v4();
let id_v7 = Uuid::now_v7();
// Encode
let encoded: String = CUuid::B64.from(id_v4);
let encoded: String = CUuid::B64.from(id_v7);
Create and encode
use grapple_utils::cuuid::CUuid;
use uuid::Uuid;
// Encode
let encoded: String = CUuid::B64.new_v4();
let encoded: String = CUuid::B64.now_v7();
Decode
use grapple_utils::cuuid::CUuid;
use uuid::Uuid;
let encoded: String = CUuid::B64.new_v4();
let id: Uuid = CUuid::B64.decode(&encoded);
For development you can create ./.cargo/config.toml file and set your variables there
# config.toml
[env]
# For single value
MY_VALUE = "my value"
# For array
MY_ARRAY = "ENV1:VALUE1,ENV2:VALUE2"
Single value loading
use grapple_utils::envs;
// If you just need to read string, use this:
let value: String = envs::get("YOUR_ENV")?;
// You also can parse value from string. Type must implement `FromStr` trait
let value: i32 = envs::get_parse("YOUR_ENV")?;
// If your value is BaseX encoded string, you can read it as
// -- BaseX decoded string bytes. Add feature `b64` to enable method
let value: Vec<u8> = envs::get_b64u_as_u8s("YOUR_ENV")?;
// -- BaseX decoded string. Add feature `b64` to enable method
let value: String = envs::get_b64u_as_s("YOUR_ENV")?;
Array of values loading
use grapple_utils::envs;
// If you need to load keys from configuration, or just an array of values, use this
let keys: HashMap<String, String> = envs::get_keys("YOUR_ENV")?;
// There are also a way to parse it as well. Type must implement `FromStr` trait
let keys: HashMap<String, i32> = envs::get_keys_parse("YOUR_ENV")?;
// If your keys encoded as BaseX, you can read it as
// -- BaseX decoded string bytes. Add feature `b64` to enable method
let keys: HashMap<String, Vec<u8>> = envs::get_keys_b64u_as_u8s("YOUR_ENV")?;
// -- BaseX decoded string. Add feature `b64` to enable method
let keys: HashMap<String, String> = envs::get_keys_b64u_as_s("YOUR_ENV")?;
There are some examples in examples folder.
Some of them requires features, so run them with:
cargo run --example <example_name> --features <feature_name>
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!
This project is licensed under the MIT License - see the LICENSE file for details.