This method will deallocate all heap memory data blocks, rendering this instance of Str effectively unusable.
(&mut self)
| 287 | /// data blocks, rendering this instance of |
| 288 | /// Str effectively unusable. |
| 289 | pub fn drop(&mut self) { |
| 290 | match self.head { |
| 291 | None => { |
| 292 | // There is nothing to deallocate |
| 293 | } |
| 294 | Some(node) => { |
| 295 | // We can deallocate this |
| 296 | let mut ptr = node; |
| 297 | loop { |
| 298 | let next = unsafe { (*ptr).next }; |
| 299 | free(ptr); |
| 300 | |
| 301 | if next.is_some() { |
| 302 | ptr = next.unwrap(); |
| 303 | } else { |
| 304 | break; |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | // Clear out all variables |
| 311 | self.head = None; |
| 312 | self.tail = None; |
| 313 | self.blocks = 0; |
| 314 | self.index = 0; |
| 315 | } |
| 316 | |
| 317 | /// Internal function to copy a certain amount of bytes |
| 318 | /// from an array into self. |