lrs-lang / lib

An experimental standard library
Mozilla Public License 2.0
225 stars 3 forks source link

Use the new placement protocol #19

Open mahkoh opened 8 years ago

mahkoh commented 8 years ago

This is mostly useful for convenience methods because you cannot recover from allocation failure. Something like this:

impl Place<T> for BoxBuf<T, H> {
    where H: alloc::Allocator,
          H::Pool: Default,
{
    fn pointer(&mut self) -> *mut T {
        /* ... */
    }
}

impl<T, H> Boxed<T> for Box<T, H>
    where H: alloc::Allocator,
          H::Pool: Default,
{
    type Data = T;
    type Place = BoxBuf<T, H>;
    unsafe fn finalize(filled: BoxBuf<T, H>) -> Box<T, H> {
        /* ... */
    }
}

impl<T, H> BoxPlace<T> for BoxBuf<T, H>
    where H: alloc::Allocator,
          H::Pool: Default,
{
    fn make_place() -> BoxBuf<T, H> {
        Box::new().unwrap()
    }
}