1 unstable release
0.1.1 | Jul 18, 2024 |
---|---|
0.1.0 |
|
#9 in #base62
9KB
83 lines
rsbase62
A high-performance, Rust-optimized Base62 encoding implementation.
Why rsbase62?
The name rsbase62
stands for "Rust Base62", highlighting several key aspects of this crate:
-
Rust-focused: This implementation is specifically optimized for Rust, taking advantage of Rust's performance characteristics and safety features where possible.
-
Clarity: The "rs" prefix clearly indicates that this is a Rust implementation, distinguishing it from Base62 libraries in other languages.
-
Discoverability: The name is easy to search for and remember, making it simple for Rust developers to find and use.
-
Specificity: It clearly communicates that this crate deals with Base62 encoding, not Base64 or other similar encodings.
Features and Advantages
- Blazing Fast: Utilizes unsafe Rust for maximum performance, making it suitable for high-throughput scenarios.
- Rust-Optimized: Designed to work seamlessly with Rust's u128 type, providing efficient encoding for large numbers.
- Minimalist: Zero dependencies for the core functionality, ensuring a light footprint in your project.
- Flexible: While optimized for performance, it can be easily wrapped in safe code for general use cases.
- Benchmark-Driven: Includes benchmarks against other Base62 implementations, demonstrating its performance benefits.
Usage
Add this to your Cargo.toml
:
[dependencies]
rsbase62 = "0.1.0"
Then, in your Rust code:
use rsbase62::encode;
fn main() {
let num: u128 = 123456789;
let encoded = unsafe { encode(num) };
println!("Encoded: {}", encoded);
}
Safety
This crate uses unsafe
code for performance optimization. It is the caller's responsibility to ensure that:
- The input is a valid u128 number
- The BASE62_CHARS array has not been modified
For safe usage, consider wrapping the encode
function in a safe API in your own code.
Benchmarks
Benchmarks comparing this implementation to other Base62 crates are included. Run them with:
cargo bench
When to Use rsbase62
- When performance is critical in your Base62 encoding operations
- In high-throughput web applications or APIs that frequently use Base62 encoding
- For projects that need to encode large numbers (up to u128) efficiently
- When you're comfortable managing unsafe code for performance gains
License
This project is licensed under
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.