diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2022-05-07 12:18:38 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2022-05-07 12:18:38 -0300 |
commit | f21e8e1bea1e93aaa22e4d6baa3a490140977617 (patch) | |
tree | 3ea65a5e9ec5d4c1f59d9f813226b65f010e7f5c /src/impls/slice.rs |
[Project] LtPtr
"Checked" raw pointers for Rust.
Diffstat (limited to 'src/impls/slice.rs')
-rw-r--r-- | src/impls/slice.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/impls/slice.rs b/src/impls/slice.rs new file mode 100644 index 0000000..ff9b9de --- /dev/null +++ b/src/impls/slice.rs @@ -0,0 +1,40 @@ + +use crate::*; + +pub trait Sealed {} +impl<T> Sealed for [T] {} + +impl<T> AsLtPtr for [T] { + type Target = T; + fn as_lt_ptr(&self) -> ConstLtPtr<'_, T> { + unsafe { ConstLtPtr::from_raw(self.as_ptr()) } + } +} + +impl<T> AsMutLtPtr for [T] { + fn as_mut_lt_ptr(&mut self) -> MutLtPtr<'_, T> { + unsafe { MutLtPtr::from_raw(self.as_mut_ptr()) } + } +} + +impl<T> SliceExt<T> for [T] { + fn as_lt_ptr_range(&self) -> Range<ConstLtPtr<'_, T>> { + let Range { start, end } = self.as_ptr_range(); + unsafe { + Range { + start: ConstLtPtr::from_raw(start), + end: ConstLtPtr::from_raw(end), + } + } + } + + fn as_mut_lt_ptr_range(&mut self) -> Range<MutLtPtr<'_, T>> { + let Range { start, end } = self.as_mut_ptr_range(); + unsafe { + Range { + start: MutLtPtr::from_raw(start), + end: MutLtPtr::from_raw(end), + } + } + } +} |