diff options
| author | mat <github@matdoes.dev> | 2021-12-15 23:10:55 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2021-12-15 23:10:55 -0600 |
| commit | 9642558f8f8d983a7087f15d68be8cf07a85f0c2 (patch) | |
| tree | 5f0a967f005cd5db510a13ab290c8ad6669b25aa /minecraft-core | |
| parent | 72aefe871ca4983431b1a0b707b472e73ffea836 (diff) | |
| download | azalea-drasl-9642558f8f8d983a7087f15d68be8cf07a85f0c2.tar.xz | |
azalea
Diffstat (limited to 'minecraft-core')
| -rw-r--r-- | minecraft-core/Cargo.toml | 9 | ||||
| -rw-r--r-- | minecraft-core/src/lib.rs | 12 | ||||
| -rw-r--r-- | minecraft-core/src/serializable_uuid.rs | 54 |
3 files changed, 0 insertions, 75 deletions
diff --git a/minecraft-core/Cargo.toml b/minecraft-core/Cargo.toml deleted file mode 100644 index e36cc03e..00000000 --- a/minecraft-core/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -edition = "2021" -name = "minecraft-core" -version = "0.1.0" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -uuid = "^0.8.2" diff --git a/minecraft-core/src/lib.rs b/minecraft-core/src/lib.rs deleted file mode 100644 index 592988a3..00000000 --- a/minecraft-core/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -//! Random miscellaneous things like UUIDs - -mod serializable_uuid; - -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - let result = 2 + 2; - assert_eq!(result, 4); - } -} diff --git a/minecraft-core/src/serializable_uuid.rs b/minecraft-core/src/serializable_uuid.rs deleted file mode 100644 index 91b5f2d8..00000000 --- a/minecraft-core/src/serializable_uuid.rs +++ /dev/null @@ -1,54 +0,0 @@ -use uuid::Uuid; - -pub trait SerializableUuid { - fn to_int_array(&self) -> [u32; 4]; - fn from_int_array(array: [u32; 4]) -> Self; -} - -// private static int[] leastMostToIntArray(long l, long l2) { -// return new int[]{(int)(l >> 32), (int)l, (int)(l2 >> 32), (int)l2}; -// } - -fn least_most_to_int_array(most: u64, least: u64) -> [u32; 4] { - [ - (most >> 32) as u32, - most as u32, - (least >> 32) as u32, - least as u32, - ] -} - -impl SerializableUuid for Uuid { - fn to_int_array(&self) -> [u32; 4] { - let most_significant_bits = (self.as_u128() >> 64) as u64; - let least_significant_bits = (self.as_u128() & 0xffffffffffffffff) as u64; - - least_most_to_int_array(most_significant_bits, least_significant_bits) - } - - fn from_int_array(array: [u32; 4]) -> Self { - let most = ((array[0] as u64) << 32) | ((array[1] as u64) & 0xFFFFFFFF); - let least = ((array[2] as u64) << 32) | ((array[3] as u64) & 0xFFFFFFFF); - - Uuid::from_u128((((most as u128) << 64) | least as u128).into()) - } -} - -mod tests { - use super::*; - - #[test] - fn to_int_array() { - let u = Uuid::parse_str("6536bfed-8695-48fd-83a1-ecd24cf2a0fd").unwrap(); - assert_eq!( - u.to_int_array(), - [0x6536bfed, 0x869548fd, 0x83a1ecd2, 0x4cf2a0fd] - ); - } - - #[test] - fn from_int_array() { - let u = Uuid::from_int_array([0x6536bfed, 0x869548fd, 0x83a1ecd2, 0x4cf2a0fd]); - assert_eq!(u.to_string(), "6536bfed-8695-48fd-83a1-ecd24cf2a0fd"); - } -} |
