This commit is contained in:
numbers
2023-09-19 19:13:55 -04:00
parent a6ba0f3e40
commit 694004ecfa
5 changed files with 9 additions and 17 deletions

View File

@@ -15,6 +15,7 @@ pub unsafe fn slicify_mut<T>(value: &mut T) -> &mut [u8] {
} }
/// converts a non mutable reference into a mutable one /// converts a non mutable reference into a mutable one
#[allow(invalid_reference_casting)]
pub unsafe fn mutify<T>(nr: &T) -> &mut T { pub unsafe fn mutify<T>(nr: &T) -> &mut T {
&mut *(nr as *const T as *mut T) &mut *(nr as *const T as *mut T)
} }

View File

@@ -37,7 +37,7 @@ pub use win32::{ image_base, image_header, find_kernel32 };
pub use xgen::signature; pub use xgen::signature;
mod time; mod time;
pub use time::*; pub use time::dur;
mod hash; mod hash;
pub use hash::*; pub use hash::*;

View File

@@ -34,19 +34,13 @@ pub mod __time_units {
} }
} }
#[allow(unused)]
#[macro_export] pub macro dur($($amount:tt $unit:ident $(,)?)+) {
macro_rules! time_unit2 { core::time::Duration::from_millis(0u64 $( + ($crate::time::time_unit!( $amount, $unit)) )+ )
(1, $unit:ident) => { $crate::__time_units::singular::$unit };
($number:literal, $unit:ident) => { $number * $crate::__time_units::plural::$unit }
} }
#[allow(unused)] #[allow(unused)]
macro time_unit( $number:tt, $unit:ident ) { macro time_unit {
crate::time_unit2!($number, $unit) (1, $unit:ident) => { $crate::time::__time_units::singular::$unit },
($number:literal, $unit:ident) => { $number * $crate::time::__time_units::plural::$unit }
} }
#[allow(unused)]
macro dur($($amount:tt $unit:ident $(,)?)+) {
core::time::Duration::from_millis(0u64 $( + (time_unit!( $amount, $unit)) )+ )
}

View File

@@ -1,10 +1,8 @@
#[test] #[test]
pub fn test_distance() { pub fn test_distance() {
let a = x::dur![ 5 days 4 hours 7 minutes 2 seconds 2 minutes ];
let a = [0u8,2,3]; let a = [0u8,2,3];
let p1 = &a[0]; let p1 = &a[0];

View File

@@ -12,7 +12,6 @@ pub fn test_image_base() {
let b = x::win32::image_base() as *const _ as usize; let b = x::win32::image_base() as *const _ as usize;
assert_eq!(a, b, "image_base didn't match"); assert_eq!(a, b, "image_base didn't match");
} }
#[test] #[test]