Crates.io | mini-functions |
lib.rs | mini-functions |
version | 0.0.10 |
source | src |
created_at | 2022-12-30 11:50:01.983059 |
updated_at | 2023-12-29 15:52:31.321837 |
description | A Rust library of highly performant utility and wrapper functions |
homepage | https://minifunctions.com |
repository | https://github.com/sebastienrousseau/mini-functions.git |
max_upload_size | |
id | 747839 |
size | 73,847 |
A Rust library of highly performant utility and wrapper functions
• Website • Documentation • Report Bug • Request Feature • Contributing Guidelines
Mini Functions
is a highly performant utility and wrapper functions library for Rust that has been carefully designed with optimization and efficiency in mind. By providing convenient wrapper functions, our library aims to provide a high-level interface for common tasks while still leveraging the performance benefits of Rust under the hood. These utility functions serve as an essential toolkit for any Rust developer, and the library's design abstractions allow for easy integration into a variety of projects and applications.
These utility functions serve as an essential toolkit for any Rust developer, and the library's design abstractions allow for easy integration into a variety of projects and applications.
Mini Functions
is a library of functions for Rust that provides a collection of tools for working with various aspects of a Rust application. The mini-functions
library consists of the following non-exhaustive
functions:
Functions | Description |
---|---|
Claims ⧉ | The Claim functions are used to retrieve and manipulate information about claims. These functions are used to create and manage claims in JSON Web Tokens (JWT) and JSON Web Signatures (JWS). |
Common ⧉ | The Common functions are used to retrieve and manipulate information about common data types. |
Date ⧉ | The Date and time functions are used to retrieve and manipulate information about dates and times. |
Errors ⧉ | The Error functions are used to retrieve and manipulate information about errors. |
Hash ⧉ | The Hash functions are used to retrieve and manipulate information about hashes. |
Logs ⧉ | The Log functions are used to retrieve and manipulate information about logs. |
JWT ⧉ | The Jot functions are used to retrieve and manipulate information about JSON Object Tokens (JOT). |
MD5 ⧉ | The MD5 functions are used to retrieve and manipulate information about MD5. |
QR ⧉ | The QR functions are used to retrieve and manipulate information about QR codes. |
Random ⧉ | The Random functions are used to retrieve and manipulate information about random data. |
See Documentation for full API details.
It takes just a few minutes to get up and running with mini-functions
.
The minimum supported Rust toolchain version is currently Rust 1.71.1 or later (stable).
To install mini-functions
, you need to have the Rust toolchain installed on your machine. You can install the Rust toolchain by following the instructions on the Rust website ⧉.
Once you have the Rust toolchain installed, you can install mini-functions
using the following command:
cargo install mini-functions
To use the mini-functions
library in your project, add the following to your Cargo.toml
file:
[dependencies]
mini-functions = "0.0.10"
Add the following to your main.rs
file:
extern crate mini_functions;
use mini_functions::*;
then you can use the functions in your application code.
The mini-functions
library comes with a set of examples that demonstrate how to use the library. You can find the examples in the examples
directory.
To run the examples, use the following command:
cargo run --example <example-name>
The mini_functions
crate provides a Claims struct for working with JWT claims.
It contains the following functions:
set_claim
to add claims.get_claim
to retrieve a claim value.remove_claim
to remove a claim.Here is a full example:
let mut claims = Claims::new();
claims.set_claim("iss", "https://example.com");
claims.set_claim("admin", "true");
let admin = claims.get_claim("admin").unwrap();
claims.remove_claim("admin");
This allows setting, retrieving, and removing JWT claims conveniently.
To run the JWT Claims example, use the following command:
cargo run --example example_claims
The mini_functions
crate provides access to common mathematical constants through the Constants
struct and cmn_constants
macro.
It contains the following functions:
Here is a full example:
use cmn::{constants::{Constant, ConstantValue}, cmn_constants};
let c = Constants::new();
let euler = c.constant("EULER").unwrap();
cmn_constants! {
PI = cmn::constants::PI,
}
println!("Euler's constant: {euler}");
println!("Pi: {PI}");
This allows convenient access to mathematical constants.
To run the constants example:
cargo run --example example_constants
The mini_functions
crate provides a DateTime
struct for working with dates and times.
It contains the following functions:
DateTime::now
- Get current date/timeDateTime::new
- Create a DateTime with default (UTC) timezoneDateTime::new_with_tz
- Create a DateTime with custom timezoneis_valid_day
- Check if a day value is validnext_day
/previous_day
- Get next/previous dayfrom_str
- Parse a date/time stringrelative_delta
- Apply a delta to the DateTimeHere is an example:
let now = DateTime::now();
let tomorrow = now + chrono::Duration::days(1);
let yesterday = now - chrono::Duration::days(1);
println!("Today: {now}");
println!("Tomorrow: {tomorrow}");
println!("Yesterday: {yesterday}");
This allows convenient date/time handling.
To run the date/time example:
cargo run --example example_date
The mini_functions
crate provides error handling functionality through the ErrorType
enum.
It contains the following functions:
ErrorType::new
- Create new error typenew_subtype
- Create error subtypeHere is an example:
use mini_functions::errors::common::ErrorType;
let error = ErrorType::new("illegal_argument");
let sub_error = error.new_subtype("invalid_value");
println!("Main error: {error:?}");
println!("Sub-error: {sub_error:?}");
This allows simple error handling with custom types and subtypes.
To run the errors example:
cargo run --example example_errors
The mini_functions
crate provides password hashing and verification functions through the Hash
struct.
It contains the following functions:
Hash::new_{algo}
- Generate a hash for a passwordset_password
- Update password for a hashverify
- Verify a password against a hashto_string
- Convert hash to a stringHere is an example:
use mini_functions::hash::Hash;
let hash = Hash::new_argon2i("mypassword");
let is_valid = hash.verify("mypassword");
let updated_hash = hash.set_password("newpassword");
let new_is_valid = updated_hash.verify("newpassword");
This allows generating and verifying password hashes conveniently.
To run the password hashing example:
cargo run --example example_hash
The mini_functions
crate provides application logging functionality through the Log
struct.
It contains functions like:
Log::new
- Create a new log entryLogFormat
- Supported log formatsHere is an example of logging events with different formats:
use mini_functions::logs::{Log, LogFormat, LogLevel};
let log_json = Log::new(
"message-id",
"2023-01-01T12:00:00Z",
LogLevel::Info,
"AppEvent",
"User logged in",
LogFormat::JSON
);
let log_clf = Log::new(
"message-id",
"2023-01-01T12:00:00Z",
LogLevel::Info,
"AuthEvent",
"User login successful",
LogFormat::CLF
);
This allows flexible logging in various text and JSON formats.
To run the logging example:
cargo run --example example_logs
The mini_functions
crate provides MD5 hash generation functionality through the MD5
struct.
It contains functions like:
MD5::hexdigest
- Generate MD5 hash for inputMD5::new
- Create MD5 hasher instanceupdate
- Update hasher with new inputfinalize
- Obtain final hashHere is an example of hashing different input sources:
use mini_functions::md5::MD5;
let digest = MD5::hexdigest("input string");
let mut hasher = MD5::new();
hasher.update(&[1, 2, 3]);
let hash = hasher.finalize();
This allows flexible hashing of strings, byte arrays, files.
To run the MD5 example:
cargo run --example example_md5
The mini_functions
crate provides QR code generation and manipulation functionality through the QRCode
struct.
It contains functions like:
QRCode::from_string
- Generate QR code from textto_png
- Convert to PNG imagecolorize
- Colorize the QR coderesize
- Resize imageAnd macros like:
qr_code_to!
- QR code generation macroHere is an example:
use mini_functions::qr;
let qr_code = qr::QRCode::from_string("https://example.com");
let img = qr_code.to_png(512);
qr::save_png(&img, "qr.png");
This allows convenient QR code creation, manipulation and saving.
To run the QR code example:
cargo run --example example_qr
The mini_functions
crate provides random number generation functionality through the Random
struct and associated functions.
It contains functions like:
Random::new
- Create random number generatorbool
- Random booleanint
- Random integerfloat
- Random floatbytes
- Random byte vectorAnd macros like:
rand_int!
- Random integer in rangerand_bool!
- Random boolean with probabilityHere is an example:
use mini_functions::random::{Random, rand_int};
let mut rng = Random::new();
let rand_num = rand_int!(rng, 0, 10);
let rand_bool = rand_bool!(rng, 0.5);
This allows convenient random number generation.
To run the random example:
cargo run --example example_random
mini-functions
is supported and tested on the following platforms:
Operating System | Target | Description | |
---|---|---|---|
✅ | Linux | aarch64-unknown-linux-gnu | 64-bit Linux systems on ARM architecture |
✅ | Windows | i686-pc-windows-gnu | 32-bit Windows systems using the GNU toolchain |
✅ | Windows | i686-pc-windows-msvc | 32-bit Windows systems using the Microsoft Visual C toolchain |
✅ | Linux | i686-unknown-linux-gnu | 32-bit Linux systems (kernel 3.2+, glibc 2.17+) |
✅ | macOS | x86_64-apple-darwin | 64-bit macOS systems (10.7 Lion or later) |
✅ | Windows | x86_64-pc-windows-gnu | 64-bit Windows systems using the GNU toolchain |
✅ | Windows | x86_64-pc-windows-msvc | 64-bit Windows systems using the Microsoft Visual C toolchain |
✅ | Linux | x86_64-unknown-linux-gnu | 64-bit Linux systems (kernel 2.6.32+, glibc 2.11+) |
Operating System | Target | Description | |
---|---|---|---|
✅ | Linux | aarch64-apple-darwin | 64-bit macOS on Apple Silicon |
✅ | Windows | aarch64-pc-windows-msvc | 64-bit Windows on ARM architecture using the Microsoft Visual C toolchain |
✅ | Linux | aarch64-unknown-linux-musl | 64-bit Linux on ARM architecture with musl libc |
✅ | Linux | arm-unknown-linux-gnueabi | ARMv6 Linux systems (kernel 3.2, glibc 2.17) |
✅ | Linux | arm-unknown-linux-gnueabihf | ARMv7 Linux systems, hardfloat (kernel 3.2, glibc 2.17) |
✅ | Linux | armv7-unknown-linux-gnueabihf | ARMv7 Linux systems, hardfloat (kernel 3.2, glibc 2.17) |
✅ | Linux | powerpc-unknown-linux-gnu | PowerPC Linux systems (kernel 3.2, glibc 2.17) |
✅ | Linux | powerpc64-unknown-linux-gnu | PowerPC64 Linux systems (kernel 3.2, glibc 2.17) |
✅ | Linux | powerpc64le-unknown-linux-gnu | PowerPC64le Linux systems (kernel 3.2, glibc 2.17) |
✅ | Linux | riscv64gc-unknown-linux-gnu | RISC-V Linux systems (kernel 3.2, glibc 2.17) |
✅ | Linux | s390x-unknown-linux-gnu | s390x Linux systems (kernel 3.2, glibc 2.17) |
✅ | Linux | x86_64-unknown-freebsd | 64-bit FreeBSD systems on x86-64 architecture |
✅ | Linux | x86_64-unknown-linux-musl | 64-bit Linux systems (kernel 2.6.32+, musl libc) |
The GitHub Actions ⧉ shows the platforms in which the mini-functions
library tests are run.
Info: Please check out our website ⧉ for more information. You can find our documentation on docs.rs ⧉, lib.rs ⧉ and crates.io ⧉.
For transparency into our release cycle and in striving to maintain backward compatibility, mini-functions
follows semantic versioning ⧉.
The project is licensed under the terms of Apache License, Version 2.0 and the MIT license.
We welcome all people who want to contribute. Please see the contributing instructions ⧉ for more information.
Contributions in any form (issues, pull requests, etc.) to this project must adhere to the Rust's Code of Conduct ⧉.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
A big thank you to all the awesome contributors of mini-functions ⧉ for their help and support.
A special thank you goes to the Rust Reddit ⧉ community for providing a lot of useful suggestions on how to improve this project.