Skip to main content

ArrowSchema

Struct ArrowSchema 

Source
pub struct ArrowSchema(/* private fields */);
Expand description

An owned Arrow C Data Interface schema.

Released on drop, unless it was already released or moved out with into_raw.

§Reading a released schema

The Arrow specification says that once release has run, every other field of the record is undefined — DuckDB’s own release callback frees the block that format, name and children point into. So format, name and child all return None once is_released is true, rather than handing out a dangling pointer.

Implementations§

Source§

impl ArrowSchema

Source

pub const fn empty() -> Self

An unfilled record, ready for a producer to write into.

release is null, so dropping one frees nothing.

Source

pub const unsafe fn from_raw(raw: RawArrowSchema) -> Self

Takes ownership of a filled ABI record.

§Safety
  • raw must be a record whose release callback this value may call exactly once, and no other wrapper may hold the same record.
  • It must be a valid Arrow C Data Interface schema: format and name null or NUL-terminated, children null or pointing at n_children valid child schemas, recursively. The safe accessors (format, name, child) and schema_from_arrow read through those pointers.
Source

pub const unsafe fn take_from(ptr: *mut RawArrowSchema) -> Self

Moves the record out of ptr, leaving a released placeholder behind.

This is how to import from another Arrow binding — arrow-rs’s FFI_ArrowSchema, say — without a double free: the source is overwritten with RawArrowSchema::empty, so its own destructor sees release == NULL and does nothing.

§Safety
  • ptr must be valid for reads and writes and properly aligned for RawArrowSchema, which every Arrow C Data Interface ArrowSchema is.
  • The caller must not use the record behind ptr afterwards, other than to drop the (now released) wrapper holding it.
  • The record behind ptr must meet from_raw’s contract: this value calls its release callback, and the safe accessors read through its pointers.
Source

pub fn into_raw(self) -> RawArrowSchema

Relinquishes ownership, returning the ABI record.

The caller becomes responsible for calling release on it.

Source

pub const fn as_ptr(&self) -> *const RawArrowSchema

A pointer to the ABI record, for C APIs that read it.

Source

pub const fn as_mut_ptr(&mut self) -> *mut RawArrowSchema

A mutable pointer to the ABI record, for C APIs that fill it.

Source

pub const fn is_released(&self) -> bool

Whether release is null — either never filled, or already released.

Source

pub fn release(&mut self)

Releases the schema now instead of at drop. Idempotent.

Source

pub fn format(&self) -> Option<&str>

The Arrow format string, e.g. "+s" for the struct at the root of a converted DuckDB schema.

None if the schema is released, the pointer is null, or the string is not valid UTF-8.

Source

pub fn name(&self) -> Option<&str>

The column name, or None when released, null, or not UTF-8.

Source

pub const fn flags(&self) -> i64

The Arrow flag bits (ARROW_FLAG_NULLABLE and friends).

Source

pub fn child_count(&self) -> usize

Number of child schemas — the column count, at the root of a converted DuckDB schema. 0 once released.

Source

pub fn child(&self, index: usize) -> Option<&Self>

Borrows child schema index.

Children are owned by this schema’s producer and released with it, which is why this borrows rather than handing out an ArrowSchema that would try to release them again.

Trait Implementations§

Source§

impl Debug for ArrowSchema

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for ArrowSchema

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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.