@@ -225,6 +225,7 @@ impl<T: GucEnum> GucSetting<T> {
225225pub struct GucRegistry { }
226226
227227impl GucRegistry {
228+ // GUC Registration functions that do not expose hooks
228229 pub fn define_bool_guc (
229230 name : & ' static CStr ,
230231 short_description : & ' static CStr ,
@@ -354,4 +355,192 @@ impl GucRegistry {
354355 ) ;
355356 }
356357 }
358+
359+ /// Define a boolean GUC with custom hooks.
360+ ///
361+ /// # Hooks
362+ ///
363+ /// * `check_hook` - Validates new values. Return false to reject.
364+ /// * `assign_hook` - Called after value is set. Use for side effects.
365+ /// * `show_hook` - Returns custom display string for SHOW commands.
366+ ///
367+ /// # Safety
368+ ///
369+ /// This function is unsafe because hook functions must be properly guarded against Rust panics.
370+ /// Any hook function that might panic must be marked with `#[pg_guard]` to ensure proper
371+ /// conversion of Rust panics into PostgreSQL errors.
372+ ///
373+ pub unsafe fn define_bool_guc_with_hooks (
374+ name : & ' static CStr ,
375+ short_description : & ' static CStr ,
376+ long_description : & ' static CStr ,
377+ setting : & ' static GucSetting < bool > ,
378+ context : GucContext ,
379+ flags : GucFlags ,
380+ check_hook : pg_sys:: GucBoolCheckHook ,
381+ assign_hook : pg_sys:: GucBoolAssignHook ,
382+ show_hook : pg_sys:: GucShowHook ,
383+ ) {
384+ unsafe {
385+ pg_sys:: DefineCustomBoolVariable (
386+ name. as_ptr ( ) ,
387+ short_description. as_ptr ( ) ,
388+ long_description. as_ptr ( ) ,
389+ setting. value . as_ptr ( ) ,
390+ setting. value . get ( ) ,
391+ context as isize as _ ,
392+ flags. bits ( ) ,
393+ check_hook,
394+ assign_hook,
395+ show_hook,
396+ ) ;
397+ }
398+ }
399+
400+ /// Define an integer GUC with custom hooks.
401+ ///
402+ /// # Safety
403+ ///
404+ /// This function is unsafe because hook functions must be properly guarded against Rust panics.
405+ /// Any hook function that might panic must be marked with `#[pg_guard]` to ensure proper
406+ /// conversion of Rust panics into PostgreSQL errors.
407+ pub unsafe fn define_int_guc_with_hooks (
408+ name : & ' static CStr ,
409+ short_description : & ' static CStr ,
410+ long_description : & ' static CStr ,
411+ setting : & ' static GucSetting < i32 > ,
412+ min_value : i32 ,
413+ max_value : i32 ,
414+ context : GucContext ,
415+ flags : GucFlags ,
416+ check_hook : pg_sys:: GucIntCheckHook ,
417+ assign_hook : pg_sys:: GucIntAssignHook ,
418+ show_hook : pg_sys:: GucShowHook ,
419+ ) {
420+ unsafe {
421+ pg_sys:: DefineCustomIntVariable (
422+ name. as_ptr ( ) ,
423+ short_description. as_ptr ( ) ,
424+ long_description. as_ptr ( ) ,
425+ setting. value . as_ptr ( ) ,
426+ setting. value . get ( ) ,
427+ min_value,
428+ max_value,
429+ context as isize as _ ,
430+ flags. bits ( ) ,
431+ check_hook,
432+ assign_hook,
433+ show_hook,
434+ )
435+ }
436+ }
437+
438+ /// Define a string GUC with custom hooks.
439+ ///
440+ /// # Safety
441+ ///
442+ /// This function is unsafe because hook functions must be properly guarded against Rust panics.
443+ /// Any hook function that might panic must be marked with `#[pg_guard]` to ensure proper
444+ /// conversion of Rust panics into PostgreSQL errors.
445+ pub unsafe fn define_string_guc_with_hooks (
446+ name : & ' static CStr ,
447+ short_description : & ' static CStr ,
448+ long_description : & ' static CStr ,
449+ setting : & ' static GucSetting < Option < CString > > ,
450+ context : GucContext ,
451+ flags : GucFlags ,
452+ check_hook : pg_sys:: GucStringCheckHook ,
453+ assign_hook : pg_sys:: GucStringAssignHook ,
454+ show_hook : pg_sys:: GucShowHook ,
455+ ) {
456+ unsafe {
457+ pg_sys:: DefineCustomStringVariable (
458+ name. as_ptr ( ) ,
459+ short_description. as_ptr ( ) ,
460+ long_description. as_ptr ( ) ,
461+ setting. value . as_ptr ( ) ,
462+ setting. value . get ( ) ,
463+ context as isize as _ ,
464+ flags. bits ( ) ,
465+ check_hook,
466+ assign_hook,
467+ show_hook,
468+ ) ;
469+ }
470+ }
471+
472+ /// Define a float GUC with custom hooks.
473+ ///
474+ /// # Safety
475+ ///
476+ /// This function is unsafe because hook functions must be properly guarded against Rust panics.
477+ /// Any hook function that might panic must be marked with `#[pg_guard]` to ensure proper
478+ /// conversion of Rust panics into PostgreSQL errors.
479+ ///
480+ pub fn define_float_guc_with_hooks (
481+ name : & ' static CStr ,
482+ short_description : & ' static CStr ,
483+ long_description : & ' static CStr ,
484+ setting : & ' static GucSetting < f64 > ,
485+ min_value : f64 ,
486+ max_value : f64 ,
487+ context : GucContext ,
488+ flags : GucFlags ,
489+ check_hook : pg_sys:: GucRealCheckHook ,
490+ assign_hook : pg_sys:: GucRealAssignHook ,
491+ show_hook : pg_sys:: GucShowHook ,
492+ ) {
493+ unsafe {
494+ pg_sys:: DefineCustomRealVariable (
495+ name. as_ptr ( ) ,
496+ short_description. as_ptr ( ) ,
497+ long_description. as_ptr ( ) ,
498+ setting. value . as_ptr ( ) ,
499+ setting. value . get ( ) ,
500+ min_value,
501+ max_value,
502+ context as isize as _ ,
503+ flags. bits ( ) ,
504+ check_hook,
505+ assign_hook,
506+ show_hook,
507+ ) ;
508+ }
509+ }
510+
511+ /// Define an enum GUC with custom hooks.
512+ ///
513+ /// # Safety
514+ ///
515+ /// This function is unsafe because hook functions must be properly guarded against Rust panics.
516+ /// Any hook function that might panic must be marked with `#[pg_guard]` to ensure proper
517+ /// conversion of Rust panics into PostgreSQL errors.
518+ pub unsafe fn define_enum_guc_with_hooks < T : GucEnum > (
519+ name : & ' static CStr ,
520+ short_description : & ' static CStr ,
521+ long_description : & ' static CStr ,
522+ setting : & ' static GucSetting < T > ,
523+ context : GucContext ,
524+ flags : GucFlags ,
525+ check_hook : pg_sys:: GucEnumCheckHook ,
526+ assign_hook : pg_sys:: GucEnumAssignHook ,
527+ show_hook : pg_sys:: GucShowHook ,
528+ ) {
529+ setting. value . set ( setting. boot_val . to_ordinal ( ) ) ;
530+ unsafe {
531+ pg_sys:: DefineCustomEnumVariable (
532+ name. as_ptr ( ) ,
533+ short_description. as_ptr ( ) ,
534+ long_description. as_ptr ( ) ,
535+ setting. value . as_ptr ( ) ,
536+ setting. value . get ( ) ,
537+ T :: CONFIG_ENUM_ENTRY ,
538+ context as isize as _ ,
539+ flags. bits ( ) ,
540+ check_hook,
541+ assign_hook,
542+ show_hook,
543+ ) ;
544+ }
545+ }
357546}
0 commit comments