base_xx
A Rust library for encoding and decoding data in various base-X formats.
Features
- Base36 encoding (0-9 and a-z)
- Base58 encoding (Bitcoin-style)
- Base64 encoding (RFC 4648)
- Hex encoding (lowercase)
- uuencode (traditional line format)
- Trait-based design for extensibility
- Zero-copy where possible
- Comprehensive error handling
- No unsafe code
Installation
Add this to your Cargo.toml:
[]
= "0.6.2"
Usage
Basic Encoding
use ;
let bytes = new;
let base36 = bytes.clone.try_encode?;
let base58 = bytes.try_encode?;
let base64 = bytes.clone.try_encode?;
let hex = bytes.clone.try_encode?;
let uuencode = bytes.try_encode?;
println!;
println!;
println!;
println!;
println!;
Implementing for Custom Types
use ;
// Now you can encode MyType
let my_data = MyType ;
let encoded = my_data.try_encode?;
Decoding
use ;
// Implement TryFrom<ByteVec> for your type
// Then implement Decodable
// Now you can decode
let encoded = new;
let decoded = try_decode?;
Supported Encodings
- Base36: Uses digits 0-9 and lowercase letters a-z. Good for case-insensitive human-readable output.
- Base58: Uses Bitcoin-style alphabet, omitting similar-looking characters. Ideal for user-facing identifiers.
- Base64: Standard Base64 encoding.
- Hex: Lowercase hexadecimal encoding.
- uuencode: Traditional uuencode line format.
Error Handling
All encoding/decoding operations return Result<T, SerialiseError>. The SerialiseError type provides detailed error information for:
- Invalid characters in input
- Unsupported encoding formats
- Size constraint violations
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Robert Forster (robert.forster@beamvex.com)