quackdb_internal/handles/
logical_type.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::ops::Deref;

use crate::{ffi, type_id::TypeId};

#[derive(Debug)]
pub struct LogicalTypeHandle {
    raw: ffi::duckdb_logical_type,
}

impl LogicalTypeHandle {
    /// # Safety
    /// * Takes ownership of `raw`
    pub unsafe fn from_raw(raw: ffi::duckdb_logical_type) -> Self {
        Self { raw }
    }
    /// # Safety
    /// * ID must not be Decimal
    pub unsafe fn from_id(type_: TypeId) -> Self {
        Self::from_raw(ffi::duckdb_create_logical_type(type_ as _))
    }
    pub fn type_id(&self) -> Option<TypeId> {
        unsafe { TypeId::from_repr(ffi::duckdb_get_type_id(self.raw)) }
    }
}

impl Deref for LogicalTypeHandle {
    type Target = ffi::duckdb_logical_type;

    fn deref(&self) -> &Self::Target {
        &self.raw
    }
}

impl Drop for LogicalTypeHandle {
    fn drop(&mut self) {
        unsafe {
            ffi::duckdb_destroy_logical_type(&mut self.raw);
        }
    }
}