From 1ff7a7a23e30eefa8ed96d9de09473012aa7bcb6 Mon Sep 17 00:00:00 2001 From: Franklin Date: Sun, 24 Mar 2024 14:39:01 +0100 Subject: [PATCH] Added convenience ext for hashing into uuid --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/hash_to_uuid_ext.rs | 12 ++++++++++++ src/lib.rs | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/hash_to_uuid_ext.rs diff --git a/Cargo.lock b/Cargo.lock index ffae816..493982b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -608,7 +608,7 @@ dependencies = [ [[package]] name = "bevy_icon_creator" -version = "0.1.1" +version = "0.1.2" dependencies = [ "bevy", ] diff --git a/Cargo.toml b/Cargo.toml index 2308899..546f83f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_icon_creator" -version = "0.1.1" +version = "0.1.2" edition = "2021" authors = ["Franklin E. Blanco"] description = "A plugin to automatically create Icons from entities/models in bevy" diff --git a/src/hash_to_uuid_ext.rs b/src/hash_to_uuid_ext.rs new file mode 100644 index 0000000..66958ae --- /dev/null +++ b/src/hash_to_uuid_ext.rs @@ -0,0 +1,12 @@ +use std::hash::{DefaultHasher, Hash, Hasher}; + +use bevy::utils::Uuid; + +pub trait HashToUuidExt: Hash { + fn to_uuid(&self) -> Uuid { + let mut default_hasher = DefaultHasher::new(); + self.hash(&mut default_hasher); + let hash = default_hasher.finish(); + Uuid::from_u128(hash as u128) + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index cc04de4..0a6f520 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ mod state; mod utils; mod set_image_on_load; mod register_types; +mod hash_to_uuid_ext; pub mod image_ext; pub mod plugin;