cj_common
A comprehensive Rust library providing essential utilities for encoding, bit manipulation, and data validation. This crate offers high-performance implementations of commonly needed functionality with both direct conversion methods and efficient iterator-based approaches.
Features
- 🔐 Base64 Encoding/Decoding - Complete Base64 support with string conversion and streaming iterators
- 🔢 Hexadecimal Encoding/Decoding - Full hex support with uppercase/lowercase options and iterator interfaces
- ⚡ Bit Manipulation - Efficient bit-level operations with get/set functionality and bit iteration
- 📊 Range Validation - Flexible in-set checking for values within ranges, slices, and collections
- 🕒 Time Utilities (feature:
timext) -OffsetDateTimeExtwith helpers liketo_primitive()to get aPrimitiveDateTime - 🚀 High Performance - Optimized implementations with zero-copy iterators where possible
- 🔧 Easy Integration - Simple prelude module for importing all functionality
Installation
Add this to your Cargo.toml:
[]
= "1.2.0"
For async channel functionality, enable the channel feature:
[]
= { = "1.2.0", = ["channel"] }
For time utilities (e.g., OffsetDateTimeExt), enable the timext feature:
[]
= { = "1.2.0", = ["timext"] }
Quick Start
The easiest way to get started is by importing the prelude module:
use *;
API Documentation
🔐 Base64 (cj_binary::b64)
Complete Base64 encoding and decoding with multiple approaches:
Direct Conversion
use *;
Iterator-Based Approach
use *;
🕒 Time Utilities (cj_helpers::timext, feature: timext)
Helpers for working with the time crate types. Currently provides OffsetDateTimeExt with methods for converting or
deriving related types.
OffsetDateTimeExt::to_primitive()— strips the offset and returns the wall-clockPrimitiveDateTime.
Enable the feature and use it like this:
= { = "1.2.0", = ["timext"] }
use OffsetDateTime;
use OffsetDateTimeExt; // trait
🔢 Hexadecimal (cj_binary::hex)
Flexible hexadecimal encoding and decoding with case options:
Note: Uppercase hex is the default output. Most methods have a corresponding
_low()variant for lowercase output (e.g.,to_hex_be_low()instead ofto_hex()).
Basic Usage
use *;
Iterator-Based Approach
use *;
⚡ Bit Manipulation (cj_binary::bitbuf)
Efficient bit-level operations with comprehensive functionality:
Basic Bit Operations
use *;
Bit Iteration
use *;
Advanced Bit Operations
use *;
📊 Range Validation (cj_helpers::in_set)
Flexible validation for checking if values exist within specified ranges or collections:
Basic Range Checking
use *;
Complex Set Validation
use *;
Performance
This crate is designed with performance in mind:
- Zero-copy iterators where possible to minimize memory allocations
- Optimized algorithms for encoding/decoding operations
- Efficient bit manipulation using native CPU instructions
- Minimal dependencies to reduce compilation time and binary size
Benchmarks
This crate includes comprehensive benchmarks to measure performance across all major functionality. The benchmarks cover:
- Base64 encoding/decoding - Both direct conversion and iterator-based approaches
- Hex encoding/decoding - String and binary data with various sizes
- Bit manipulation - Get/set operations and bit iteration across different integer types
- Range validation - Simple range checks and complex set operations
Running Benchmarks
To run the benchmarks:
This will generate detailed performance reports and HTML output (if available) showing timing comparisons across different operations and data sizes.
Benchmark Results
The benchmarks test various scenarios including:
- Small vs. large data sets
- String vs. binary data encoding
- Direct function calls vs. iterator-based processing
- Different integer types for bit operations
Results are displayed with statistical analysis including confidence intervals and outlier detection.
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE_APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE_MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.