Skip to main content

TypedScalarFunctionBuilder

Struct TypedScalarFunctionBuilder 

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

A scalar function built from a safe Rust closure, ready to register.

Returned by ScalarFunctionBuilder::map1 and its siblings. The SQL signature is fixed by the closure’s type, so this builder deliberately has no returns, param, function, extra_info, bind or init: each of those could make DuckDB hand the closure vectors of a different type than it reads and writes.

ⓘ
use quack_rs::scalar::ScalarFunctionBuilder;
use quack_rs::types::TypeId;

// An i64 result cannot be redeclared as a 4-byte INTEGER.
let _ = ScalarFunctionBuilder::map1("widen", |x: i64| x + 1)?.returns(TypeId::Integer);
ⓘ
use quack_rs::scalar::ScalarFunctionBuilder;

quack_rs::scalar_callback!(other, |_info, _input, _output| {});

// The trampoline cannot be swapped out from under the closure's state.
let _ = ScalarFunctionBuilder::map1("f", |x: i64| x)?.function(other);

Implementations§

Source§

impl TypedScalarFunctionBuilder

Source

pub fn name(&self) -> &str

Returns the function name.

Source

pub fn volatile(self) -> Self

Marks this function as volatile: re-evaluated for every row even when its arguments are constant (e.g. a random-number function).

Only the function’s stability changes; its signature does not.

Source

pub unsafe fn register( self, con: duckdb_connection, ) -> Result<(), ExtensionError>

Registers the function on the given connection.

§Errors

Returns ExtensionError if a scalar function with this name and parameter types already exists (which DuckDB would silently replace or make ambiguous), or if DuckDB reports a registration failure — for example, the name belongs to an aggregate function or a macro. See ScalarFunctionBuilder::register for the collision rules.

§Safety

con must be a valid, open duckdb_connection.

Trait Implementations§

Source§

impl Debug for TypedScalarFunctionBuilder

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.