Merge branch 'master' into szabodanika
This commit is contained in:
commit
c6e5c6f018
10 changed files with 91 additions and 18 deletions
18
src/util/hashids.rs
Normal file
18
src/util/hashids.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use harsh::Harsh;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref HARSH: Harsh = Harsh::builder().length(6).build().unwrap();
|
||||
}
|
||||
|
||||
pub fn to_hashids(number: u64) -> String {
|
||||
HARSH.encode(&[number])
|
||||
}
|
||||
|
||||
pub fn to_u64(hash_id: &str) -> Result<u64, &str> {
|
||||
let ids = HARSH
|
||||
.decode(hash_id)
|
||||
.map_err(|_e| "Failed to decode hash ID")?;
|
||||
let id = ids.get(0).ok_or("No ID found in hash ID")?;
|
||||
Ok(*id)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue