Destroy a `DeviceBuffer`, returning an error. Deallocating device memory can return errors from previous asynchronous work. This function destroys the given buffer and returns the error and the un-destroyed buffer on failure. # Example ``` # let _context = cust::quick_init().unwrap(); use cust::memory::*; let x = DeviceBuffer::from_slice(&[10, 20, 30]).unwrap(); match DeviceBuffer::drop(x) { Ok
(mut dev_buf: DeviceBuffer<T>)
| 187 | /// } |
| 188 | /// ``` |
| 189 | pub fn drop(mut dev_buf: DeviceBuffer<T>) -> DropResult<DeviceBuffer<T>> { |
| 190 | if dev_buf.buf.is_null() { |
| 191 | return Ok(()); |
| 192 | } |
| 193 | |
| 194 | if dev_buf.len > 0 && size_of::<T>() > 0 { |
| 195 | let capacity = dev_buf.len; |
| 196 | let ptr = mem::replace(&mut dev_buf.buf, DevicePointer::null()); |
| 197 | unsafe { |
| 198 | match cuda_free(ptr) { |
| 199 | Ok(()) => { |
| 200 | mem::forget(dev_buf); |
| 201 | Ok(()) |
| 202 | } |
| 203 | Err(e) => Err((e, DeviceBuffer::from_raw_parts(ptr, capacity))), |
| 204 | } |
| 205 | } |
| 206 | } else { |
| 207 | Ok(()) |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | #[cfg(feature = "bytemuck")] |
nothing calls this directly
no test coverage detected