Skip to main content

CopyGlobalInitInfo

Struct CopyGlobalInitInfo 

Source
pub struct CopyGlobalInitInfo { /* private fields */ }
Expand description

Wrapper around the duckdb_copy_function_global_init_info handle provided to a copy function global init callback.

Implementations§

Source§

impl CopyGlobalInitInfo

Source

pub const unsafe fn new(info: duckdb_copy_function_global_init_info) -> Self

Wraps a raw duckdb_copy_function_global_init_info handle.

§Safety

info must be a valid handle passed by DuckDB to a copy function global init callback.

Source

pub unsafe fn get_bind_data(&self) -> *mut c_void

Retrieves the bind data pointer set during the bind phase.

§Safety

The returned pointer must be cast back to the original type.

Source

pub unsafe fn get_extra_info(&self) -> *mut c_void

Retrieves the extra-info pointer previously set on the copy function.

§Safety

The returned pointer is only valid as long as the copy function is registered and DuckDB has not yet called the destructor.

Source

pub unsafe fn get_file_path(&self) -> Result<String, ExtensionError>

Returns the destination path for the copy operation.

The returned String is a copy. DuckDB keeps ownership of its own buffer — duckdb_copy_function_global_init_get_file_path returns info_ref.file_path.c_str(), the interior pointer of a live C++ std::string, so it must not be freed. Doing so corrupts the heap.

§Errors

Returns an error if the path is not valid UTF-8, which a path on Linux need not be (COPY t TO '~/out.x' with a non-UTF-8 home directory, for one). A lossy conversion would name a different file, so use get_file_path_bytes to open such a path.

§Safety

self.info must be a valid handle from an active callback invocation.

Source

pub unsafe fn get_file_path_bytes(&self) -> Vec<u8> ⓘ

Returns the destination path for the copy operation as the exact bytes DuckDB holds, whatever their encoding (empty if DuckDB has none).

On Unix, std::ffi::OsStr::from_bytes turns them into a path that opens the same file. See get_file_path for the ownership of DuckDB’s buffer.

§Safety

self.info must be a valid handle from an active callback invocation.

Source

pub unsafe fn set_global_state( &self, state: *mut c_void, destroy: duckdb_delete_callback_t, )

Sets the global state pointer and its destructor.

§Safety

state must remain valid until DuckDB calls destroy, or for the lifetime of the query if destroy is None.

Source

pub fn set_global_state_typed<T: Send + Sync + 'static>(&self, state: T)

Stores state as this statement’s global state: the safe, typed form of set_global_state. Read it with global_state_ref in the sink and finalize callbacks.

The destructor is generated and panic-safe, as for CopyBindInfo::set_bind_data_typed, and DuckDB runs it once when the statement ends, also after a sink or finalize error. T is Send + Sync because the sink can run on several threads at once: state they change needs a Mutex or atomics inside T. A FileHandle kept here belongs in a Mutex (see its docs on keeping a file open across callbacks). Call this at most once per global init.

Source

pub unsafe fn bind_data_ref<T: 'static>(&self) -> Option<&T>

Borrows the bind data set with CopyBindInfo::set_bind_data_typed as a T; None when none was set or it holds another type.

§Safety

The bind data, if any, was set through set_bind_data_typed, not the raw set_bind_data, whose pointer carries no type tag.

Source

pub unsafe fn extra_info_ref<T: 'static>(&self) -> Option<&T>

Borrows the copy function’s extra info as a T; see CopyBindInfo::extra_info_ref.

§Safety

As for CopyBindInfo::extra_info_ref.

Source

pub fn set_error(&self, message: &str)

Reports a fatal error, causing DuckDB to abort the current query.

An interior null byte in message is replaced by ?, and an empty message by EMPTY_ERROR_PLACEHOLDER.

Source

pub unsafe fn get_client_context(&self) -> ClientContext

Returns the client context for this callback.

§Safety

The inner handle must be valid (requires DuckDB runtime), and the returned context must not be used after the connection running this query is closed — see ClientContext.

Source

pub const fn as_raw(&self) -> duckdb_copy_function_global_init_info

Returns the underlying raw handle.

Trait Implementations§

Source§

impl Debug for CopyGlobalInitInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.