//! The no-op allocator. All operations fail when they actually need to allocate.
//! Use this when you just want to wrap some pointer but still get all the boilerplate
//! from allocator-aware data structures. (i.e a hypothetical `Vec<u8, NoopAlloc>`)

use core::prelude::*;
use core::mem;
use core::num::Int;
pub use allocator::{Allocator};

pub struct NoopAlloc;

impl Copy for NoopAlloc {}

impl Allocator for NoopAlloc {
    unsafe fn alloc<T>(&mut self, _count: uint) -> Option<*mut T> { 
        None 
    }

    unsafe fn calloc<T>(&mut self, _items: uint) -> Option<*mut T> { 
        None 
    }

    unsafe fn realloc<T>(&mut self, _buf: &mut *mut T, current: uint, items: uint) -> Option<uint> {
        if current >= items {
            Some(current)
        } else {
            None
        }
    }

    unsafe fn ensure<T>(&mut self, _buf: &mut *mut T, current: uint, min: uint) -> Option<uint> {
        if current >= min {
            Some(current)
        } else {
            None
        }
    }

    unsafe fn free<T>(&mut self, _buf: *mut T, _count: uint) {}
}