ps_buffer/methods/free.rs
1use std::ptr::null_mut;
2
3use ps_alloc::{free, DeallocationError};
4
5use crate::Buffer;
6
7impl Buffer {
8 /// Deallocates this `Buffer`.
9 /// # Errors
10 /// `DeallocationError` is returned if calling [`ps_alloc::free`] fails.
11 pub fn free(&mut self) -> Result<&mut Self, DeallocationError> {
12 let ptr = self.ptr;
13
14 self.capacity = 0;
15 self.length = 0;
16 self.ptr = null_mut();
17
18 match free(ptr) {
19 Ok(()) | Err(DeallocationError::NullPtr) => Ok(self),
20 Err(err) => Err(err)?,
21 }
22 }
23}