ps-buffer 0.1.0-21

aligned heap buffer
Documentation
use std::ptr::null_mut;

use ps_alloc::{free, DeallocationError};

use crate::Buffer;

impl Buffer {
    /// Deallocates this `Buffer`.
    /// # Errors
    /// `DeallocationError` is returned if calling [`ps_alloc::free`] fails.
    pub fn free(&mut self) -> Result<&mut Self, DeallocationError> {
        let ptr = self.ptr;

        self.capacity = 0;
        self.length = 0;
        self.ptr = null_mut();

        match unsafe { free(ptr) } {
            Ok(()) | Err(DeallocationError::NullPtr) => Ok(self),
            Err(err) => Err(err)?,
        }
    }
}