Would using u128 be more efficient than using byte array of the same size in Rust if we only compare for equality?
⚓ Rust 📅 2025-08-03 👤 surdeus 👁️ 12I'm working with a bioinformatics application that handles many IDs. These IDs are well-defined and always shorter than 16 characters, so they can easily fit into a u128. Currently, I'm using String to represent these IDs, but I'm getting tired of constantly cloning them or carefully following Rust's borrowing rules. It's becoming appealing to use a data type that implements Copy, like integers, which would simplify things significantly.
An array such as [u8; 16] also implements Copy, making the code more flexible. If I suddenly encounter an unusually long ID that doesn't fit, I could simply reserve a larger array. But would using u128 be significantly more efficient than a byte array?
I'd like to ask someone with more profound knowledge of how Rust handles these data structures internally. I'm considering creating a new short_id crate specifically for managing short, string-like IDs, complete with convenient methods for conversion to and from various representations.
3 posts - 3 participants
🏷️ Rust_feed