| Crates.io | base62 |
| lib.rs | base62 |
| version | 2.2.3 |
| created_at | 2015-10-13 12:48:26.376761+00 |
| updated_at | 2025-09-21 02:28:10.839018+00 |
| description | A Base62 encoding/decoding library |
| homepage | https://github.com/fbernier/base62 |
| repository | https://github.com/fbernier/base62 |
| max_upload_size | |
| id | 3212 |
| size | 74,972 |
A fast, zero-dependency base62 encoder/decoder library for Rust, typically used in URL shorteners. It supports both standard [0-9A-Za-z] and alternative [0-9a-zA-Z] variants.
no_std compatible with optional alloc and std supportu128Add this to your Cargo.toml:
[dependencies]
base62 = "2"
use base62;
// Encoding
let encoded = base62::encode(1234567890);
assert_eq!(encoded, "1LY7VK");
// Decoding
let decoded = base62::decode("1LY7VK").unwrap();
assert_eq!(decoded, 1234567890);
The crate works in no_std environments by default:
#![no_std]
use base62;
// Encode into a fixed buffer
let mut buf = [0u8; 22]; // Maximum size needed for u128
let len = base62::encode_bytes(1234567890, &mut buf).unwrap();
assert_eq!(&buf[..len], b"1LY7VK");
// Decode from bytes
let decoded = base62::decode(&buf[..len]).unwrap();
assert_eq!(decoded, 1234567890);
alloc: Enables String allocation support (enabled by default)std: Enables std::io traits supportThe library is optimized for both encoding and decoding performance:
Licensed under the MIT license. See LICENSE for details.