#![allow(unused_imports)]
use std::{
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
};
use crate::prelude::BuildWith;
use super::Id;
#[derive(Debug, Clone, PartialEq, Hash)]
pub struct Key(String);
impl Key {
pub fn id(&self) -> Id {
let mut hasher = DefaultHasher::new();
self.hash(&mut hasher);
Id(hasher.finish())
}
}
impl Default for Key {
fn default() -> Self {
Self(format!("default::{:020}", rand::random::<u64>()))
}
}
impl BuildWith<i8> for Key {
fn with(param: i8) -> Self {
Self(format!("{:020}", param))
}
}
impl BuildWith<i16> for Key {
fn with(param: i16) -> Self {
Self(format!("{:020}", param))
}
}
impl BuildWith<i32> for Key {
fn with(param: i32) -> Self {
Self(format!("{:020}", param))
}
}
impl BuildWith<i64> for Key {
fn with(param: i64) -> Self {
Self(format!("{:020}", param))
}
}
impl BuildWith<u8> for Key {
fn with(param: u8) -> Self {
Self(format!("{:020}", param))
}
}
impl BuildWith<u16> for Key {
fn with(param: u16) -> Self {
Self(format!("{:020}", param))
}
}
impl BuildWith<u32> for Key {
fn with(param: u32) -> Self {
Self(format!("{:020}", param))
}
}
impl BuildWith<u64> for Key {
fn with(param: u64) -> Self {
Self(format!("{:020}", param))
}
}
impl BuildWith<usize> for Key {
fn with(param: usize) -> Self {
Self(format!("{:020}", param))
}
}
impl BuildWith<&str> for Key {
fn with(param: &str) -> Self {
Self(param.to_owned())
}
}
impl BuildWith<String> for Key {
fn with(param: String) -> Self {
Self(param)
}
}
impl BuildWith<Key> for Key {
fn with(param: Key) -> Self {
Self(format!("{}::{:020}", ¶m.0, rand::random::<u64>()))
}
}
impl BuildWith<&Key> for Key {
fn with(param: &Key) -> Self {
Self(format!("{}::{:020}", ¶m.0, rand::random::<u64>()))
}
}