summary refs log tree commit diff stats
path: root/src/impls/slice.rs
blob: ff9b9de54c152f71ccc05484c7d67e3b977eb93f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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),
            }
        }
    }
}