flowbrigade 0.1.4

Rust bindings for FlowBrigade's C ABI.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
use std::ffi::{c_char, c_double, c_int, c_void};

pub const FB_OK: c_int = 0;
pub const FB_ERR_INVALID_ARGUMENT: c_int = 1;
pub const FB_ERR_BUFFER_TOO_SMALL: c_int = 2;
pub const FB_ERR_INTERNAL: c_int = 100;

pub const FB_NO_JITTER: c_int = 0;
pub const FB_FULL_JITTER: c_int = 1;
pub const FB_EQUAL_JITTER: c_int = 2;
pub const FB_DECORRELATED_JITTER: c_int = 3;

pub type FbBackoffPolicy = *mut c_void;
pub type FbTokenBucket = *mut c_void;
pub type FbGcraLimiter = *mut c_void;
pub type FbFixedWindow = *mut c_void;
pub type FbKeyedFixedWindow = *mut c_void;
pub type FbKeyedGcraLimiter = *mut c_void;
pub type FbSlidingWindow = *mut c_void;
pub type FbCircuitBreaker = *mut c_void;
pub type FbBulkhead = *mut c_void;
pub type FbKeyedBulkhead = *mut c_void;
pub type FbTimeout = *mut c_void;
pub type FbDeadline = *mut c_void;
pub type FbBudgetLedger = *mut c_void;
pub type FbRetryAllowance = *mut c_void;
pub type FbLockStore = *mut c_void;
pub type FbLockLease = *mut c_void;
pub type FbThrottle = *mut c_void;
pub type FbDebouncer = *mut c_void;
pub type FbLimiterRegistry = *mut c_void;

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct FbRateLimitResult {
    pub allowed: c_int,
    pub limit: c_int,
    pub remaining: c_int,
    pub retry_after_ns: i64,
    pub reset_after_ns: i64,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct FbBulkheadResult {
    pub allowed: c_int,
    pub capacity: c_int,
    pub in_use: c_int,
    pub remaining: c_int,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct FbBudgetResult {
    pub allowed: c_int,
    pub limit: i64,
    pub used: i64,
    pub remaining: i64,
    pub cost: i64,
    pub retry_after_ns: i64,
    pub reset_after_ns: i64,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct FbRetryAllowanceResult {
    pub allowed: c_int,
    pub limit: i64,
    pub originals: i64,
    pub retries: i64,
    pub remaining: i64,
    pub cost: i64,
    pub retry_after_ns: i64,
    pub reset_after_ns: i64,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct FbLockAcquireResult {
    pub acquired: c_int,
    pub ttl_ns: i64,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct FbLockStatus {
    pub held: c_int,
    pub expired: c_int,
    pub ttl_ns: i64,
    pub remaining_ns: i64,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct FbRetryResult {
    pub succeeded: c_int,
    pub attempts: c_int,
    pub last_status: c_int,
    pub last_delay_ns: i64,
}

#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct FbFallbackResult {
    pub succeeded: c_int,
    pub attempts: c_int,
    pub provider_index: c_int,
    pub failed_count: c_int,
    pub last_status: c_int,
}

pub type FbRetryOperation = unsafe extern "C" fn(*mut c_void, c_int) -> c_int;
pub type FbRetrySleep = unsafe extern "C" fn(*mut c_void, i64, c_int) -> c_int;
pub type FbFallbackOperation = unsafe extern "C" fn(*mut c_void, c_int) -> c_int;
pub type FbFallbackPredicate = unsafe extern "C" fn(*mut c_void, c_int, c_int) -> c_int;
pub type FbFixedWindowStorageOperation = unsafe extern "C" fn(
    *mut c_void,
    *const c_char,
    usize,
    c_int,
    i64,
    c_int,
    i64,
    *mut FbRateLimitResult,
) -> c_int;
pub type FbFixedWindowStorageClear =
    unsafe extern "C" fn(*mut c_void, *const c_char, usize, *mut c_int) -> c_int;

#[repr(C)]
#[derive(Clone, Copy)]
pub struct FbFallbackProvider {
    pub operation: Option<FbFallbackOperation>,
    pub user_data: *mut c_void,
    pub breaker: *mut c_void,
}

#[repr(C)]
#[derive(Clone, Copy)]
pub struct FbRateLimitStorage {
    pub inspect_fixed_window: Option<FbFixedWindowStorageOperation>,
    pub consume_fixed_window: Option<FbFixedWindowStorageOperation>,
    pub clear_fixed_window: Option<FbFixedWindowStorageClear>,
    pub user_data: *mut c_void,
}

extern "C" {
    pub fn NimMain();

    pub fn fb_abi_version() -> c_int;
    pub fn fb_abi_version_string() -> *const c_char;
    pub fn fb_abi_supports(
        feature: *const c_char,
        feature_len: usize,
        out_supported: *mut c_int,
    ) -> c_int;
    pub fn fb_last_error() -> *const c_char;

    pub fn fb_duration_parse(input: *const c_char, input_len: usize, out_ns: *mut i64) -> c_int;
    pub fn fb_duration_format(
        duration_ns: i64,
        buffer: *mut c_char,
        buffer_len: usize,
        out_len: *mut usize,
    ) -> c_int;
    pub fn fb_rate_limit_result_to_json(
        result: *const FbRateLimitResult,
        buffer: *mut c_char,
        buffer_len: usize,
        out_len: *mut usize,
    ) -> c_int;
    pub fn fb_rate_limit_result_to_prometheus(
        result: *const FbRateLimitResult,
        buffer: *mut c_char,
        buffer_len: usize,
        out_len: *mut usize,
    ) -> c_int;
    pub fn fb_budget_result_to_json(
        result: *const FbBudgetResult,
        key: *const c_char,
        key_len: usize,
        buffer: *mut c_char,
        buffer_len: usize,
        out_len: *mut usize,
    ) -> c_int;
    pub fn fb_budget_result_to_prometheus(
        result: *const FbBudgetResult,
        key: *const c_char,
        key_len: usize,
        buffer: *mut c_char,
        buffer_len: usize,
        out_len: *mut usize,
    ) -> c_int;

    pub fn fb_fixed_backoff_create(
        delay_ns: i64,
        jitter: c_int,
        out_handle: *mut FbBackoffPolicy,
    ) -> c_int;
    pub fn fb_linear_backoff_create(
        initial_ns: i64,
        increment_ns: i64,
        max_delay_ns: i64,
        jitter: c_int,
        out_handle: *mut FbBackoffPolicy,
    ) -> c_int;
    pub fn fb_exp_backoff_create(
        initial_ns: i64,
        factor: c_double,
        max_delay_ns: i64,
        jitter: c_int,
        out_handle: *mut FbBackoffPolicy,
    ) -> c_int;
    pub fn fb_backoff_destroy(handle: FbBackoffPolicy);
    pub fn fb_backoff_delay_for(
        handle: FbBackoffPolicy,
        attempt: c_int,
        out_delay_ns: *mut i64,
    ) -> c_int;

    pub fn fb_token_bucket_create(
        rate: c_int,
        per_ns: i64,
        burst: c_int,
        out_handle: *mut FbTokenBucket,
    ) -> c_int;
    pub fn fb_token_bucket_destroy(handle: FbTokenBucket);
    pub fn fb_token_bucket_inspect(
        handle: FbTokenBucket,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_token_bucket_consume(
        handle: FbTokenBucket,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_token_bucket_reset(handle: FbTokenBucket) -> c_int;
    pub fn fb_token_bucket_configured_rate(handle: FbTokenBucket, out_rate: *mut c_int) -> c_int;
    pub fn fb_token_bucket_configured_period(
        handle: FbTokenBucket,
        out_period_ns: *mut i64,
    ) -> c_int;
    pub fn fb_token_bucket_configured_burst(handle: FbTokenBucket, out_burst: *mut c_int) -> c_int;
    pub fn fb_token_bucket_available_tokens(handle: FbTokenBucket, out_tokens: *mut c_int)
        -> c_int;

    pub fn fb_gcra_create(
        rate: c_int,
        per_ns: i64,
        burst: c_int,
        out_handle: *mut FbGcraLimiter,
    ) -> c_int;
    pub fn fb_gcra_destroy(handle: FbGcraLimiter);
    pub fn fb_gcra_inspect(
        handle: FbGcraLimiter,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_gcra_consume(
        handle: FbGcraLimiter,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_gcra_allow(handle: FbGcraLimiter, cost: c_int, out_allowed: *mut c_int) -> c_int;
    pub fn fb_gcra_reset(handle: FbGcraLimiter) -> c_int;
    pub fn fb_gcra_configured_rate(handle: FbGcraLimiter, out_rate: *mut c_int) -> c_int;
    pub fn fb_gcra_configured_period(handle: FbGcraLimiter, out_period_ns: *mut i64) -> c_int;
    pub fn fb_gcra_configured_burst(handle: FbGcraLimiter, out_burst: *mut c_int) -> c_int;
    pub fn fb_gcra_configured_interval(handle: FbGcraLimiter, out_interval_ns: *mut i64) -> c_int;
    pub fn fb_gcra_available_capacity(handle: FbGcraLimiter, out_capacity: *mut c_int) -> c_int;

    pub fn fb_fixed_window_create(
        limit: c_int,
        per_ns: i64,
        out_handle: *mut FbFixedWindow,
    ) -> c_int;
    pub fn fb_fixed_window_destroy(handle: FbFixedWindow);
    pub fn fb_fixed_window_inspect(
        handle: FbFixedWindow,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_fixed_window_consume(
        handle: FbFixedWindow,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_fixed_window_reset(handle: FbFixedWindow) -> c_int;
    pub fn fb_fixed_window_configured_limit(handle: FbFixedWindow, out_limit: *mut c_int) -> c_int;
    pub fn fb_fixed_window_configured_period(
        handle: FbFixedWindow,
        out_period_ns: *mut i64,
    ) -> c_int;
    pub fn fb_fixed_window_in_use(handle: FbFixedWindow, out_in_use: *mut c_int) -> c_int;

    pub fn fb_keyed_fixed_window_create(
        limit: c_int,
        per_ns: i64,
        max_keys: c_int,
        out_handle: *mut FbKeyedFixedWindow,
    ) -> c_int;
    pub fn fb_keyed_fixed_window_destroy(handle: FbKeyedFixedWindow);
    pub fn fb_keyed_fixed_window_inspect(
        handle: FbKeyedFixedWindow,
        key: *const c_char,
        key_len: usize,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_keyed_fixed_window_consume(
        handle: FbKeyedFixedWindow,
        key: *const c_char,
        key_len: usize,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_keyed_fixed_window_clear(
        handle: FbKeyedFixedWindow,
        key: *const c_char,
        key_len: usize,
        out_cleared: *mut c_int,
    ) -> c_int;
    pub fn fb_keyed_fixed_window_reset(
        handle: FbKeyedFixedWindow,
        key: *const c_char,
        key_len: usize,
        out_reset: *mut c_int,
    ) -> c_int;
    pub fn fb_keyed_fixed_window_reset_all(
        handle: FbKeyedFixedWindow,
        out_removed: *mut c_int,
    ) -> c_int;
    pub fn fb_keyed_fixed_window_active_keys(
        handle: FbKeyedFixedWindow,
        out_count: *mut c_int,
    ) -> c_int;
    pub fn fb_keyed_fixed_window_configured_limit(
        handle: FbKeyedFixedWindow,
        out_limit: *mut c_int,
    ) -> c_int;
    pub fn fb_keyed_fixed_window_configured_period(
        handle: FbKeyedFixedWindow,
        out_period_ns: *mut i64,
    ) -> c_int;
    pub fn fb_keyed_fixed_window_key_capacity(
        handle: FbKeyedFixedWindow,
        out_capacity: *mut c_int,
    ) -> c_int;

    pub fn fb_keyed_gcra_create(
        rate: c_int,
        per_ns: i64,
        burst: c_int,
        max_keys: c_int,
        out_handle: *mut FbKeyedGcraLimiter,
    ) -> c_int;
    pub fn fb_keyed_gcra_destroy(handle: FbKeyedGcraLimiter);
    pub fn fb_keyed_gcra_inspect(
        handle: FbKeyedGcraLimiter,
        key: *const c_char,
        key_len: usize,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_keyed_gcra_consume(
        handle: FbKeyedGcraLimiter,
        key: *const c_char,
        key_len: usize,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_keyed_gcra_allow(
        handle: FbKeyedGcraLimiter,
        key: *const c_char,
        key_len: usize,
        cost: c_int,
        out_allowed: *mut c_int,
    ) -> c_int;
    pub fn fb_keyed_gcra_prune_idle(handle: FbKeyedGcraLimiter) -> c_int;
    pub fn fb_keyed_gcra_active_keys(handle: FbKeyedGcraLimiter, out_count: *mut c_int) -> c_int;
    pub fn fb_keyed_gcra_clear(
        handle: FbKeyedGcraLimiter,
        key: *const c_char,
        key_len: usize,
        out_cleared: *mut c_int,
    ) -> c_int;
    pub fn fb_keyed_gcra_reset(
        handle: FbKeyedGcraLimiter,
        key: *const c_char,
        key_len: usize,
        out_reset: *mut c_int,
    ) -> c_int;
    pub fn fb_keyed_gcra_reset_all(handle: FbKeyedGcraLimiter, out_removed: *mut c_int) -> c_int;
    pub fn fb_keyed_gcra_configured_rate(handle: FbKeyedGcraLimiter, out_rate: *mut c_int)
        -> c_int;
    pub fn fb_keyed_gcra_configured_period(
        handle: FbKeyedGcraLimiter,
        out_period_ns: *mut i64,
    ) -> c_int;
    pub fn fb_keyed_gcra_configured_burst(
        handle: FbKeyedGcraLimiter,
        out_burst: *mut c_int,
    ) -> c_int;
    pub fn fb_keyed_gcra_configured_interval(
        handle: FbKeyedGcraLimiter,
        out_interval_ns: *mut i64,
    ) -> c_int;
    pub fn fb_keyed_gcra_key_capacity(
        handle: FbKeyedGcraLimiter,
        out_capacity: *mut c_int,
    ) -> c_int;

    pub fn fb_sliding_window_create(
        limit: c_int,
        per_ns: i64,
        out_handle: *mut FbSlidingWindow,
    ) -> c_int;
    pub fn fb_sliding_window_destroy(handle: FbSlidingWindow);
    pub fn fb_sliding_window_inspect(
        handle: FbSlidingWindow,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_sliding_window_consume(
        handle: FbSlidingWindow,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_sliding_window_reset(handle: FbSlidingWindow) -> c_int;
    pub fn fb_sliding_window_configured_limit(
        handle: FbSlidingWindow,
        out_limit: *mut c_int,
    ) -> c_int;
    pub fn fb_sliding_window_configured_period(
        handle: FbSlidingWindow,
        out_period_ns: *mut i64,
    ) -> c_int;
    pub fn fb_sliding_window_current_use(handle: FbSlidingWindow, out_in_use: *mut c_int) -> c_int;

    pub fn fb_circuit_breaker_create(
        failure_threshold: c_int,
        reset_after_ns: i64,
        out_handle: *mut FbCircuitBreaker,
    ) -> c_int;
    pub fn fb_circuit_breaker_destroy(handle: FbCircuitBreaker);
    pub fn fb_circuit_breaker_allow(handle: FbCircuitBreaker, out_allowed: *mut c_int) -> c_int;
    pub fn fb_circuit_breaker_record_success(handle: FbCircuitBreaker) -> c_int;
    pub fn fb_circuit_breaker_record_failure(handle: FbCircuitBreaker) -> c_int;
    pub fn fb_circuit_breaker_state(handle: FbCircuitBreaker, out_state: *mut c_int) -> c_int;

    pub fn fb_bulkhead_create(capacity: c_int, out_handle: *mut FbBulkhead) -> c_int;
    pub fn fb_bulkhead_destroy(handle: FbBulkhead);
    pub fn fb_bulkhead_inspect(handle: FbBulkhead, out_result: *mut FbBulkheadResult) -> c_int;
    pub fn fb_bulkhead_acquire(handle: FbBulkhead, out_result: *mut FbBulkheadResult) -> c_int;
    pub fn fb_bulkhead_release(handle: FbBulkhead) -> c_int;

    pub fn fb_keyed_bulkhead_create(
        capacity: c_int,
        max_keys: c_int,
        out_handle: *mut FbKeyedBulkhead,
    ) -> c_int;
    pub fn fb_keyed_bulkhead_destroy(handle: FbKeyedBulkhead);
    pub fn fb_keyed_bulkhead_inspect(
        handle: FbKeyedBulkhead,
        key: *const c_char,
        key_len: usize,
        out_result: *mut FbBulkheadResult,
    ) -> c_int;
    pub fn fb_keyed_bulkhead_acquire(
        handle: FbKeyedBulkhead,
        key: *const c_char,
        key_len: usize,
        out_result: *mut FbBulkheadResult,
    ) -> c_int;
    pub fn fb_keyed_bulkhead_release(
        handle: FbKeyedBulkhead,
        key: *const c_char,
        key_len: usize,
    ) -> c_int;
    pub fn fb_keyed_bulkhead_clear(
        handle: FbKeyedBulkhead,
        key: *const c_char,
        key_len: usize,
        out_cleared: *mut c_int,
    ) -> c_int;
    pub fn fb_keyed_bulkhead_active_keys(handle: FbKeyedBulkhead, out_count: *mut c_int) -> c_int;

    pub fn fb_timeout_create(after_ns: i64, out_handle: *mut FbTimeout) -> c_int;
    pub fn fb_timeout_destroy(handle: FbTimeout);
    pub fn fb_timeout_expired(handle: FbTimeout, out_expired: *mut c_int) -> c_int;
    pub fn fb_timeout_elapsed(handle: FbTimeout, out_elapsed_ns: *mut i64) -> c_int;
    pub fn fb_timeout_remaining(handle: FbTimeout, out_remaining_ns: *mut i64) -> c_int;

    pub fn fb_deadline_create(after_ns: i64, out_handle: *mut FbDeadline) -> c_int;
    pub fn fb_deadline_destroy(handle: FbDeadline);
    pub fn fb_deadline_expired(handle: FbDeadline, out_expired: *mut c_int) -> c_int;
    pub fn fb_deadline_remaining(handle: FbDeadline, out_remaining_ns: *mut i64) -> c_int;
    pub fn fb_deadline_clamp(
        handle: FbDeadline,
        requested_ns: i64,
        out_clamped_ns: *mut i64,
    ) -> c_int;

    pub fn fb_budget_ledger_create(
        limit: i64,
        per_ns: i64,
        out_handle: *mut FbBudgetLedger,
    ) -> c_int;
    pub fn fb_budget_ledger_destroy(handle: FbBudgetLedger);
    pub fn fb_budget_inspect(
        handle: FbBudgetLedger,
        key: *const c_char,
        key_len: usize,
        cost: i64,
        out_result: *mut FbBudgetResult,
    ) -> c_int;
    pub fn fb_budget_consume(
        handle: FbBudgetLedger,
        key: *const c_char,
        key_len: usize,
        cost: i64,
        out_result: *mut FbBudgetResult,
    ) -> c_int;
    pub fn fb_budget_refund(
        handle: FbBudgetLedger,
        key: *const c_char,
        key_len: usize,
        amount: i64,
        out_result: *mut FbBudgetResult,
    ) -> c_int;
    pub fn fb_budget_reset(
        handle: FbBudgetLedger,
        key: *const c_char,
        key_len: usize,
        out_result: *mut FbBudgetResult,
    ) -> c_int;
    pub fn fb_budget_reset_all(handle: FbBudgetLedger) -> c_int;

    pub fn fb_retry_allowance_create(
        retry_ratio: c_double,
        per_ns: i64,
        minimum_retries: i64,
        max_keys: c_int,
        out_handle: *mut FbRetryAllowance,
    ) -> c_int;
    pub fn fb_retry_allowance_destroy(handle: FbRetryAllowance);
    pub fn fb_retry_allowance_record_original(
        handle: FbRetryAllowance,
        key: *const c_char,
        key_len: usize,
        amount: i64,
        out_result: *mut FbRetryAllowanceResult,
    ) -> c_int;
    pub fn fb_retry_allowance_inspect_retry(
        handle: FbRetryAllowance,
        key: *const c_char,
        key_len: usize,
        cost: i64,
        out_result: *mut FbRetryAllowanceResult,
    ) -> c_int;
    pub fn fb_retry_allowance_record_retry(
        handle: FbRetryAllowance,
        key: *const c_char,
        key_len: usize,
        cost: i64,
        out_result: *mut FbRetryAllowanceResult,
    ) -> c_int;
    pub fn fb_retry_allowance_allow_retry(
        handle: FbRetryAllowance,
        key: *const c_char,
        key_len: usize,
        cost: i64,
        out_allowed: *mut c_int,
    ) -> c_int;
    pub fn fb_retry_allowance_clear(
        handle: FbRetryAllowance,
        key: *const c_char,
        key_len: usize,
        out_cleared: *mut c_int,
    ) -> c_int;
    pub fn fb_retry_allowance_reset(
        handle: FbRetryAllowance,
        key: *const c_char,
        key_len: usize,
        out_reset: *mut c_int,
    ) -> c_int;
    pub fn fb_retry_allowance_reset_all(handle: FbRetryAllowance, out_removed: *mut c_int)
        -> c_int;
    pub fn fb_retry_allowance_prune_expired(handle: FbRetryAllowance) -> c_int;
    pub fn fb_retry_allowance_active_keys(handle: FbRetryAllowance, out_count: *mut c_int)
        -> c_int;
    pub fn fb_retry_allowance_configured_retry_ratio(
        handle: FbRetryAllowance,
        out_ratio: *mut c_double,
    ) -> c_int;
    pub fn fb_retry_allowance_configured_minimum_retries(
        handle: FbRetryAllowance,
        out_minimum_retries: *mut i64,
    ) -> c_int;
    pub fn fb_retry_allowance_configured_period(
        handle: FbRetryAllowance,
        out_period_ns: *mut i64,
    ) -> c_int;
    pub fn fb_retry_allowance_key_capacity(
        handle: FbRetryAllowance,
        out_capacity: *mut c_int,
    ) -> c_int;

    pub fn fb_lock_store_create(out_handle: *mut FbLockStore) -> c_int;
    pub fn fb_lock_store_destroy(handle: FbLockStore);
    pub fn fb_lock_lease_destroy(handle: FbLockLease);
    pub fn fb_lock_acquire(
        handle: FbLockStore,
        key: *const c_char,
        key_len: usize,
        ttl_ns: i64,
        out_lease: *mut FbLockLease,
        out_result: *mut FbLockAcquireResult,
    ) -> c_int;
    pub fn fb_lock_release(
        handle: FbLockStore,
        lease: FbLockLease,
        out_released: *mut c_int,
    ) -> c_int;
    pub fn fb_lock_release_key(
        handle: FbLockStore,
        key: *const c_char,
        key_len: usize,
        out_released: *mut c_int,
    ) -> c_int;
    pub fn fb_lock_refresh(
        handle: FbLockStore,
        lease: FbLockLease,
        ttl_ns: i64,
        out_result: *mut FbLockAcquireResult,
    ) -> c_int;
    pub fn fb_lock_inspect(
        handle: FbLockStore,
        lease: FbLockLease,
        out_status: *mut FbLockStatus,
    ) -> c_int;

    pub fn fb_throttle_create(every_ns: i64, out_handle: *mut FbThrottle) -> c_int;
    pub fn fb_throttle_destroy(handle: FbThrottle);
    pub fn fb_throttle_allow(handle: FbThrottle, out_allowed: *mut c_int) -> c_int;
    pub fn fb_throttle_reset(handle: FbThrottle) -> c_int;

    pub fn fb_debouncer_create(delay_ns: i64, out_handle: *mut FbDebouncer) -> c_int;
    pub fn fb_debouncer_destroy(handle: FbDebouncer);
    pub fn fb_debouncer_call(handle: FbDebouncer) -> c_int;
    pub fn fb_debouncer_ready(handle: FbDebouncer, out_ready: *mut c_int) -> c_int;
    pub fn fb_debouncer_consume_ready(handle: FbDebouncer, out_ready: *mut c_int) -> c_int;
    pub fn fb_debouncer_cancel(handle: FbDebouncer) -> c_int;

    pub fn fb_retry_run(
        policy: FbBackoffPolicy,
        max_attempts: c_int,
        operation: Option<FbRetryOperation>,
        sleep: Option<FbRetrySleep>,
        user_data: *mut c_void,
        out_result: *mut FbRetryResult,
    ) -> c_int;
    pub fn fb_fallback_run(
        providers: *const FbFallbackProvider,
        provider_count: usize,
        should_fallback: Option<FbFallbackPredicate>,
        out_result: *mut FbFallbackResult,
    ) -> c_int;

    pub fn fb_limiter_registry_create(out_handle: *mut FbLimiterRegistry) -> c_int;
    pub fn fb_limiter_registry_destroy(handle: FbLimiterRegistry);
    pub fn fb_limiter_registry_add_fixed_window(
        handle: FbLimiterRegistry,
        name: *const c_char,
        name_len: usize,
        limit: c_int,
        per_ns: i64,
    ) -> c_int;
    pub fn fb_limiter_registry_add_sliding_window(
        handle: FbLimiterRegistry,
        name: *const c_char,
        name_len: usize,
        limit: c_int,
        per_ns: i64,
    ) -> c_int;
    pub fn fb_limiter_registry_add_token_bucket(
        handle: FbLimiterRegistry,
        name: *const c_char,
        name_len: usize,
        rate: c_int,
        per_ns: i64,
        burst: c_int,
    ) -> c_int;
    pub fn fb_limiter_registry_add_keyed_fixed_window(
        handle: FbLimiterRegistry,
        name: *const c_char,
        name_len: usize,
        limit: c_int,
        per_ns: i64,
        max_keys: c_int,
    ) -> c_int;
    pub fn fb_limiter_registry_add_stored_fixed_window(
        handle: FbLimiterRegistry,
        name: *const c_char,
        name_len: usize,
        prefix: *const c_char,
        prefix_len: usize,
        limit: c_int,
        per_ns: i64,
        storage: *const FbRateLimitStorage,
        max_key_length: c_int,
    ) -> c_int;
    pub fn fb_limiter_registry_add_compound(
        handle: FbLimiterRegistry,
        name: *const c_char,
        name_len: usize,
        child_names: *const *const c_char,
        child_name_lens: *const usize,
        child_count: usize,
    ) -> c_int;
    pub fn fb_limiter_registry_inspect(
        handle: FbLimiterRegistry,
        name: *const c_char,
        name_len: usize,
        key: *const c_char,
        key_len: usize,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_limiter_registry_consume(
        handle: FbLimiterRegistry,
        name: *const c_char,
        name_len: usize,
        key: *const c_char,
        key_len: usize,
        cost: c_int,
        out_result: *mut FbRateLimitResult,
    ) -> c_int;
    pub fn fb_limiter_registry_allow(
        handle: FbLimiterRegistry,
        name: *const c_char,
        name_len: usize,
        key: *const c_char,
        key_len: usize,
        cost: c_int,
        out_allowed: *mut c_int,
    ) -> c_int;
    pub fn fb_limiter_registry_clear(
        handle: FbLimiterRegistry,
        name: *const c_char,
        name_len: usize,
        key: *const c_char,
        key_len: usize,
        out_cleared: *mut c_int,
    ) -> c_int;
}