range func

This commit is contained in:
Intege-rs
2025-04-12 23:25:45 -04:00
parent e0165ab294
commit 1a742a4c90
2 changed files with 16 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
use crate::cast_traits::As;
use core::cmp::Ordering; use core::cmp::Ordering;
use core::mem::MaybeUninit; use core::mem::MaybeUninit;
use crate::cast_traits::As;
/// Converts reference of struct to binary slice /// Converts reference of struct to binary slice
#[inline(always)] #[inline(always)]
@@ -16,7 +16,6 @@ pub unsafe fn slicify_mut<T>(value: &mut T) -> &mut [u8] {
core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<T>()) core::slice::from_raw_parts_mut(ptr, core::mem::size_of::<T>())
} }
/// converts a non mutable reference into a mutable one /// converts a non mutable reference into a mutable one
#[inline(always)] #[inline(always)]
pub unsafe fn mutify<T>(nr: &T) -> &mut T { pub unsafe fn mutify<T>(nr: &T) -> &mut T {
@@ -46,7 +45,20 @@ pub fn distance(p1: impl As<usize>, p2: impl As<usize>) -> usize {
} }
} }
/// Utility function to create ranges from the start + length
pub fn range<T: core::ops::Add<Output=T> + Copy>(
start: impl As<T>,
len: impl As<T>
) -> core::ops::Range<T> {
let s = start.cast();
let l = len.cast();
s..s + l
}
pub unsafe trait Zeroed: Sized { pub unsafe trait Zeroed: Sized {
#[inline(always)] #[inline(always)]
fn zeroed() -> Self { unsafe { core::mem::zeroed() } } fn zeroed() -> Self {
unsafe { core::mem::zeroed() }
}
} }

View File

@@ -40,6 +40,7 @@ pub mod prelude {
slicify_mut, slicify_mut,
statify, statify,
statify_mut, statify_mut,
range,
Zeroed Zeroed
}; };
pub use crate::arrays::{ pub use crate::arrays::{