+#![allow(unused)]
+
use std::marker::PhantomData;
use std::ptr::NonNull;
_unsafe_to_construct: (),
}
-/*impl Deref for NoAliasSingleton {
+impl NoAliasSingleton {
+ pub fn as_mut<'a>(&'a mut self) -> NoAlias<'a> {
+ NoAlias(PhantomData)
+ }
+}
+
+/*impl Deref for
type Target = NoAlias<'a>;
fn deref(
} */
// Not Clone or Copy
pub struct NoAlias<'a>(
- PhantomData(&'a mut NoAliasSingleton),
+ PhantomData<&'a mut NoAliasSingleton>,
);
impl<'a> NoAlias<'a> {
pub fn reborrow<'s: 'a>(&'s mut self) -> NoAlias<'a> {
+ todo!()
}
}
-#[derive(Copy)]
pub struct Ptr<T> {
// invariant over T?
// XXXX check variance
ptr: NonNull<T>,
}
+impl<T> Clone for Ptr<T> {
+ fn clone(&self) -> Self { *self }
+}
+impl<T> Copy for Ptr<T> {}
+
impl<T> Ptr<T> {
- pub fn new(t: T) -> Self { .. }
+ pub fn new_heap(t: T) -> Self { todo!() }
/*
/// SAFETY
///
/// You must not call `deallocate` on the return value.
TODO lifetime is hard
- pub unsafe fn new_borrowed<'t>(t: Pin<&'t mut T>) -> Self { .. }
+ pub unsafe fn new_borrowed<'t>(t: Pin<&'t mut T>) -> Self { todo!() }
*/
#[inline]
- pub fn borrow<'na>(self, na: &'na NoAlias<'na>) -> &'na T { .. }
+ pub fn borrow<'na>(self, na: &'na NoAlias<'na>) -> &'na T { todo!() }
#[inline]
- pub fn borrow_mut<'na>(self, g: &mut NoAlias<'na>) -> &'na mut T { .. }
+ pub fn borrow_mut<'na>(self, g: &mut NoAlias<'na>) -> &'na mut T {
+ todo!()
+ }
+
+ /// Useful if you want to compare pointers, or something
+ pub fn as_ptr(self) -> NonNull<T> {
+ self.ptr
+ }
///
///
/// ("used" means passed to any method in this library).
///
/// (The compiler will check that no borrows are live.)
- pub unsafe fn free(self, g: &mut NoAlias) -> T { .. }
+ pub unsafe fn free_heap(self, g: &mut NoAlias) -> T { todo!() }
}
-struct MultiAccessor<'a, R, const N: usize> {
-}
+/*struct MultiAccessor<'a, R, const N: usize> {
+}*/
impl NoAliasSingleton {
/// # SAFETY
//
// 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 { .. }
+ pub unsafe fn init() -> Self { todo!() }
}
impl<'a> NoAlias<'a> {
-
- pub fn multi(&mut self) -> MultiAccessor<(), 0> { .. }
+/*
+ pub fn multi(&mut self) -> MultiAccessor<(), 0> { todo!() }
+*/
}
/*
impl MultiAccessor<'a, R, const N: usize> {
- pub fn finish(self) -> R { .. }
+ pub fn finish(self) -> R { todo!() }
pub fn borrow<T>(self, p: &mut NoAlias
*/
use super::*;
mod list {
+ use super::*;
+
pub struct Node<T> {
- back: Option<Ptr<Node>>,
- next: Option<Ptr<Node>>,
+ back: Option<Ptr<Node<T>>>,
+ next: Option<Ptr<Node<T>>>,
pub data: T,
}
pub struct List<T> {
- head: Option<Ptr<Node>>,
- tail: Option<Ptr<Node>>,
+ head: Option<Ptr<Node<T>>>,
+ tail: Option<Ptr<Node<T>>>,
noalias: NoAliasSingleton,
}
impl<T> List<T> {
pub fn new() -> Self {
- let noalias = unsafe { NoAliasSingleton::new() };
+ let noalias = unsafe { NoAliasSingleton::init() };
List { head: None, tail: None, noalias }
}
data,
};
let node = Ptr::new_heap(node);
- self.tail = node;
- if self.head == None { self.head = node };
+ self.tail = Some(node);
+ if self.head.is_none() { self.head = Some(node) };
}
pub fn pop_front(&mut self) -> Option<T> {
- let noalias = &mut self.noalias;
+ let mut noalias = self.noalias.as_mut();
+ let noalias = &mut noalias;
+
let deleting = self.head?;
- let new_head = node.borrow(noalias);
+ let new_head = deleting.borrow(noalias).next;
self.head = new_head;
if let Some(new_head) = new_head {
- new_head.borrow_mut(&mut self.noalias).back = None;
+ new_head.borrow_mut(noalias).back = None;
} else {
self.tail = None;
}
- deleting.free(noalias)
+ let deleted = unsafe { deleting.free_heap(noalias) };
+ Some(deleted.data)
}
}
#[test]
fn demo() {
- let l = List::new();
+ use list::List;
+
+ let l = List::<String>::new();
drop(l);
let mut l = List::new();