@@ -23,10 +23,10 @@ pub use arrow::{ArrowFunctionSignature, ArrowScalarParams, VArrowScalar};
2323
2424/// Duckdb scalar function trait
2525pub trait VScalar : Sized {
26- /// State set at registration time. Persists for the lifetime of the catalog entry.
26+ /// Extra info set at registration time. Persists for the lifetime of the catalog entry.
2727 /// Shared across worker threads and invocations — must not be modified during execution.
2828 /// Must be `'static` as it is stored in DuckDB and may outlive the current stack frame.
29- type State : Sized + Send + Sync + ' static ;
29+ type ExtraInfo : Sized + Send + Sync + ' static ;
3030 /// The actual function
3131 ///
3232 /// # Safety
@@ -36,7 +36,7 @@ pub trait VScalar: Sized {
3636 /// - Dereferences multiple raw pointers (`func`).
3737 ///
3838 unsafe fn invoke (
39- state : & Self :: State ,
39+ extra_info : & Self :: ExtraInfo ,
4040 input : & mut DataChunkHandle ,
4141 output : & mut dyn WritableVector ,
4242 ) -> Result < ( ) , Box < dyn std:: error:: Error > > ;
@@ -110,7 +110,7 @@ impl From<duckdb_function_info> for ScalarFunctionInfo {
110110}
111111
112112impl ScalarFunctionInfo {
113- pub unsafe fn get_scalar_extra_info < T > ( & self ) -> & T {
113+ pub unsafe fn get_extra_info < T > ( & self ) -> & T {
114114 & * ( duckdb_scalar_function_get_extra_info ( self . 0 ) . cast ( ) )
115115 }
116116
@@ -126,44 +126,48 @@ where
126126{
127127 let info = ScalarFunctionInfo :: from ( info) ;
128128 let mut input = DataChunkHandle :: new_unowned ( input) ;
129- let result = T :: invoke ( info. get_scalar_extra_info ( ) , & mut input, & mut output) ;
129+ let result = T :: invoke ( info. get_extra_info ( ) , & mut input, & mut output) ;
130130 if let Err ( e) = result {
131131 info. set_error ( & e. to_string ( ) ) ;
132132 }
133133}
134134
135135impl Connection {
136- /// Register the given ScalarFunction with default state .
136+ /// Register the given ScalarFunction with default extra info .
137137 #[ inline]
138138 pub fn register_scalar_function < S : VScalar > ( & self , name : & str ) -> crate :: Result < ( ) >
139139 where
140- S :: State : Default ,
140+ S :: ExtraInfo : Default ,
141141 {
142142 let set = ScalarFunctionSet :: new ( name) ;
143143 for signature in S :: signatures ( ) {
144144 let scalar_function = ScalarFunction :: new ( name) ?;
145145 signature. register_with_scalar ( & scalar_function) ;
146146 scalar_function. set_function ( Some ( scalar_func :: < S > ) ) ;
147- scalar_function. set_extra_info ( S :: State :: default ( ) ) ;
147+ scalar_function. set_extra_info ( S :: ExtraInfo :: default ( ) ) ;
148148 set. add_function ( scalar_function) ?;
149149 }
150150 self . db . borrow_mut ( ) . register_scalar_function_set ( set)
151151 }
152152
153- /// Register the given ScalarFunction with custom state .
153+ /// Register the given ScalarFunction with custom extra info .
154154 ///
155- /// The state is cloned once per function signature (overload) and stored in DuckDB's catalog.
155+ /// The extra info is cloned once per function signature (overload) and stored in DuckDB's catalog.
156156 #[ inline]
157- pub fn register_scalar_function_with_state < S : VScalar > ( & self , name : & str , state : & S :: State ) -> crate :: Result < ( ) >
157+ pub fn register_scalar_function_with_extra_info < S : VScalar > (
158+ & self ,
159+ name : & str ,
160+ extra_info : & S :: ExtraInfo ,
161+ ) -> crate :: Result < ( ) >
158162 where
159- S :: State : Clone ,
163+ S :: ExtraInfo : Clone ,
160164 {
161165 let set = ScalarFunctionSet :: new ( name) ;
162166 for signature in S :: signatures ( ) {
163167 let scalar_function = ScalarFunction :: new ( name) ?;
164168 signature. register_with_scalar ( & scalar_function) ;
165169 scalar_function. set_function ( Some ( scalar_func :: < S > ) ) ;
166- scalar_function. set_extra_info ( state . clone ( ) ) ;
170+ scalar_function. set_extra_info ( extra_info . clone ( ) ) ;
167171 set. add_function ( scalar_function) ?;
168172 }
169173 self . db . borrow_mut ( ) . register_scalar_function_set ( set)
@@ -196,10 +200,10 @@ mod test {
196200 struct ErrorScalar { }
197201
198202 impl VScalar for ErrorScalar {
199- type State = ( ) ;
203+ type ExtraInfo = ( ) ;
200204
201205 unsafe fn invoke (
202- _: & Self :: State ,
206+ _: & Self :: ExtraInfo ,
203207 input : & mut DataChunkHandle ,
204208 _: & mut dyn WritableVector ,
205209 ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
@@ -234,10 +238,10 @@ mod test {
234238 struct EchoScalar { }
235239
236240 impl VScalar for EchoScalar {
237- type State = TestState ;
241+ type ExtraInfo = TestState ;
238242
239243 unsafe fn invoke (
240- state : & Self :: State ,
244+ extra_info : & Self :: ExtraInfo ,
241245 input : & mut DataChunkHandle ,
242246 output : & mut dyn WritableVector ,
243247 ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
@@ -250,7 +254,7 @@ mod test {
250254 let output = output. flat_vector ( ) ;
251255
252256 for s in strings {
253- let res = format ! ( "{}: {}" , state . prefix, s. repeat( state . multiplier) ) ;
257+ let res = format ! ( "{}: {}" , extra_info . prefix, s. repeat( extra_info . multiplier) ) ;
254258 output. insert ( 0 , res. as_str ( ) ) ;
255259 }
256260 Ok ( ( ) )
@@ -267,10 +271,10 @@ mod test {
267271 struct Repeat { }
268272
269273 impl VScalar for Repeat {
270- type State = ( ) ;
274+ type ExtraInfo = ( ) ;
271275
272276 unsafe fn invoke (
273- _: & Self :: State ,
277+ _: & Self :: ExtraInfo ,
274278 input : & mut DataChunkHandle ,
275279 output : & mut dyn WritableVector ,
276280 ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
@@ -317,9 +321,9 @@ mod test {
317321 }
318322 }
319323
320- // Test with custom state
324+ // Test with custom extra info
321325 {
322- conn. register_scalar_function_with_state :: < EchoScalar > (
326+ conn. register_scalar_function_with_extra_info :: < EchoScalar > (
323327 "echo2" ,
324328 & TestState {
325329 multiplier : 5 ,
0 commit comments