+use std::marker::PhantomData;
+use std::ptr::NonNull;
+
// Not Clone or Copy
pub struct NoAliasSingleton {
_unsafe_to_construct: (),
}
-impl Deref for NoAliasSingleton {
+/*impl Deref for NoAliasSingleton {
type Target = NoAlias<'a>;
fn deref(
-}
+} */
// Not Clone or Copy
-pub struct NoAlias<a'>(
- PhantomData(&mut NoAliasSingleton),
+pub struct NoAlias<'a>(
+ PhantomData(&'a mut NoAliasSingleton),
);
impl<'a> NoAlias<'a> {
#[derive(Copy)]
pub struct Ptr<T> {
- // invariant over T
- ptr: NonZero<T>,
+ // invariant over T?
+ // XXXX check variance
+ ptr: NonNull<T>,
}
impl<T> Ptr<T> {
*/
#[inline]
- pub fn borrow(self, g: &NoAlias) -> Ref<T> { .. }
+ pub fn borrow<'na>(self, na: &'na NoAlias<'na>) -> &'na T { .. }
#[inline]
- pub fn borrow_mut(self, g: &mut NoAlias) -> RefMut<T> { .. }
+ pub fn borrow_mut<'na>(self, g: &mut NoAlias<'na>) -> &'na mut T { .. }
///
///
pub unsafe fn free(self, g: &mut NoAlias) -> T { .. }
}
-impl<T> Deref for Ref<T> {
- type Target = T;
-}
-impl<T> DerefMut for RefMut<T> {
- type Target = T;
-}
-
struct MultiAccessor<'a, R, const N: usize> {
}
-impl NoAlias {
+impl NoAliasSingleton {
/// # SAFETY
///
- /// There must be only one `NoAlias` used with each `Ptr`.
+ /// There must be only one `NoAliasSingleton` used with each `Ptr`.
///
/// That is, it is unsound to use the same `Ptr` (or any copy of it)
- /// with two (or more) different `NoAlias`es.
+ /// with `NoAlias`es derived from
+ /// two (or more) different `NoAliasSingleton`s.
///
- /// The easiest way to do this is to have only one `NoAlias`.
+ /// The easiest way to do this is to have only one `NoAliasSingleton`.
///
/// If this rule is violated, `borrow` and `borrow_mut` can be instant-UB.
//
// I haven't been able to think of a practical safe API,
// but one only needs about 1 call to init_unchecked.
pub unsafe fn init_unchecked() -> Self { .. }
+}
+
+impl<'a> NoAlias<'a> {
pub fn multi(&mut self) -> MultiAccessor<(), 0> { .. }
}
+/*
impl MultiAccessor<'a, R, const N: usize> {
pub fn finish(self) -> R { .. }
pub fn borrow<T>(self, p: &mut NoAlias
-
-
-pub fn add(left: u64, right: u64) -> u64 {
- left + right
-}
+*/
#[cfg(test)]
mod tests {
drop(l);
}
}
+
+