polars_core/chunked_array/
drop.rs

1use crate::chunked_array::object::extension::drop::drop_list;
2use crate::prelude::*;
3
4#[inline(never)]
5#[cold]
6fn drop_slow<T: PolarsDataType>(ca: &mut ChunkedArray<T>) {
7    // SAFETY:
8    // guarded by the type system
9    // the transmute only convinces the type system that we are a list
10    #[allow(clippy::transmute_undefined_repr)]
11    unsafe {
12        drop_list(std::mem::transmute::<&mut ChunkedArray<T>, &ListChunked>(
13            ca,
14        ))
15    }
16}
17
18impl<T: PolarsDataType> Drop for ChunkedArray<T> {
19    fn drop(&mut self) {
20        if matches!(self.dtype(), DataType::List(_)) {
21            drop_slow(self);
22        }
23    }
24}