dbn 0.54.0

Library for working with Databento Binary Encoding (DBN)
Documentation
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
//! Helper macros for working with multiple RTypes, Schemas, and types of records.

// Re-export
pub use dbn_macros::{
    dbn_record, CsvSerialize, DbnAttr, JsonSerialize, PyFieldDesc, RecordDebug, WritePyRepr,
};

/// Base macro for type dispatch based on rtype.
///
/// # Errors
/// This macro returns an error if the rtype is not recognized.
#[doc(hidden)]
#[macro_export]
macro_rules! rtype_dispatch_base {
    ($rec_ref:expr, $handler:ident) => {{
        // Introduced new scope so new `use`s are ok
        use $crate::enums::RType;
        use $crate::record::*;
        match $rec_ref.rtype() {
            Ok(RType::Mbp0) => Ok($handler!(TradeMsg)),
            Ok(RType::Mbp1) => Ok($handler!(Mbp1Msg)),
            Ok(RType::Mbp10) => Ok($handler!(Mbp10Msg)),
            #[allow(deprecated)]
            Ok(RType::OhlcvDeprecated)
            | Ok(RType::Ohlcv1S)
            | Ok(RType::Ohlcv1M)
            | Ok(RType::Ohlcv1H)
            | Ok(RType::Ohlcv1D)
            | Ok(RType::OhlcvEod) => Ok($handler!(OhlcvMsg)),
            Ok(RType::Imbalance) => Ok($handler!(ImbalanceMsg)),
            Ok(RType::Status) => Ok($handler!(StatusMsg)),
            Ok(RType::InstrumentDef)
                if $rec_ref.record_size() < std::mem::size_of::<$crate::v2::InstrumentDefMsg>() =>
            {
                Ok($handler!($crate::v1::InstrumentDefMsg))
            }
            Ok(RType::InstrumentDef)
                if $rec_ref.record_size() < std::mem::size_of::<$crate::v3::InstrumentDefMsg>() =>
            {
                Ok($handler!($crate::v2::InstrumentDefMsg))
            }
            Ok(RType::InstrumentDef) => Ok($handler!($crate::v3::InstrumentDefMsg)),
            Ok(RType::SymbolMapping)
                if $rec_ref.record_size() < std::mem::size_of::<SymbolMappingMsg>() =>
            {
                Ok($handler!($crate::v1::SymbolMappingMsg))
            }
            Ok(RType::SymbolMapping) => Ok($handler!(SymbolMappingMsg)),
            Ok(RType::Error) if $rec_ref.record_size() < std::mem::size_of::<ErrorMsg>() => {
                Ok($handler!($crate::v1::ErrorMsg))
            }
            Ok(RType::Error) => Ok($handler!(ErrorMsg)),
            Ok(RType::System) if $rec_ref.record_size() < std::mem::size_of::<SystemMsg>() => {
                Ok($handler!($crate::v1::SystemMsg))
            }
            Ok(RType::System) => Ok($handler!(SystemMsg)),
            Ok(RType::Statistics)
                if $rec_ref.record_size() < std::mem::size_of::<$crate::v3::StatMsg>() =>
            {
                Ok($handler!($crate::v1::StatMsg))
            }
            Ok(RType::Statistics) => Ok($handler!($crate::v3::StatMsg)),
            Ok(RType::Mbo) => Ok($handler!(MboMsg)),
            Ok(RType::Cmbp1) | Ok(RType::Tcbbo) => Ok($handler!(Cmbp1Msg)),
            Ok(RType::Bbo1S) | Ok(RType::Bbo1M) => Ok($handler!(BboMsg)),
            Ok(RType::Cbbo1S) | Ok(RType::Cbbo1M) => Ok($handler!(CbboMsg)),
            Err(e) => Err(e),
        }
    }};
}

/// Dispatches to a generic function or method based on `$rtype` and optionally `$ts_out`.
///
/// # Panics
/// This function will panic if the encoded length of the given record is shorter
/// than expected for its `rtype`.
///
/// # Errors
/// This macro returns an error if the rtype is not recognized.
#[macro_export]
macro_rules! rtype_dispatch {
    // generic async method
    ($rec_ref:expr, $this:ident.$generic_method:ident($($arg:expr),*).await$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $this.$generic_method($rec_ref.get::<$r>().unwrap() $(, $arg)*).await
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
    // generic method
    ($rec_ref:expr, $this:ident.$generic_method:ident($($arg:expr),*)$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $this.$generic_method($rec_ref.get::<$r>().unwrap() $(, $arg)*)
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
    // generic async function
    ($rec_ref:expr, $generic_fn:ident($($arg:expr),*).await$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $generic_fn($rec_ref.get::<$r>().unwrap() $(, $arg)*).await
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
    // generic function
    ($rec_ref:expr, $generic_fn:ident($($arg:expr),*)$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $generic_fn($rec_ref.get::<$r>().unwrap() $(, $arg)*)
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
    // generic always ts_out async method
    ($rec_ref:expr, ts_out: true, $this:ident.$generic_method:ident($($arg:expr),*).await$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $this.$generic_method($rec_ref.get::<$crate::WithTsOut<$r>>().unwrap() $(, $arg)*).await
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
    // generic always ts_out method
    ($rec_ref:expr, ts_out: true, $this:ident.$generic_method:ident($($arg:expr),*)$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $this.$generic_method($rec_ref.get::<$crate::WithTsOut<$r>>().unwrap(), $(, $arg)*)
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
    // generic always ts_out async function
    ($rec_ref:expr, ts_out: true, $generic_fn:ident($($arg:expr),*).await$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $generic_fn($rec_ref.get::<$crate::WithTsOut<$r>>().unwrap() $(, $arg)*).await
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
    // generic always ts_out function
    ($rec_ref:expr, ts_out: true, $generic_fn:ident($($arg:expr),*)$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $generic_fn($rec_ref.get::<$crate::WithTsOut<$r>>().unwrap() $(, $arg)*)
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
    // ts_out generic async method
    ($rec_ref:expr, ts_out: $ts_out:expr, $this:ident.$generic_method:ident($($arg:expr),*).await$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                if $ts_out {
                    $this.$generic_method($rec_ref.get::<$crate::WithTsOut<$r>>().unwrap() $(, $arg)*).await
                } else {
                    $this.$generic_method($rec_ref.get::<$r>().unwrap() $(, $arg)*).await
                }
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
    // ts_out generic method
    ($rec_ref:expr, ts_out: $ts_out:expr, $this:ident.$generic_method:ident($($arg:expr),*)$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                if $ts_out {
                    $this.$generic_method($rec_ref.get::<$crate::WithTsOut<$r>>().unwrap() $(, $arg)*)
                } else {
                    $this.$generic_method($rec_ref.get::<$r>().unwrap() $(, $arg)*)
                }
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
    // ts_out generic async function
    ($rec_ref:expr, ts_out: $ts_out:expr, $generic_fn:ident($($arg:expr),*).await$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                if $ts_out {
                    $generic_fn($rec_ref.get::<$crate::WithTsOut<$r>>().unwrap() $(, $arg)*).await
                } else {
                    $generic_fn($rec_ref.get::<$r>().unwrap() $(, $arg)*).await
                }
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
    // ts_out generic function
    ($rec_ref:expr, ts_out: $ts_out:expr, $generic_fn:ident($($arg:expr),*)$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                if $ts_out {
                    $generic_fn($rec_ref.get::<$crate::WithTsOut<$r>>().unwrap() $(, $arg)*)
                } else {
                    $generic_fn($rec_ref.get::<$r>().unwrap() $(, $arg)*)
                }
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
}

#[doc(hidden)]
#[macro_export]
macro_rules! schema_dispatch_base {
    ($schema:expr, $handler:ident) => {{
        use $crate::enums::Schema;
        use $crate::record::*;
        match $schema {
            Schema::Mbo => $handler!(MboMsg),
            Schema::Mbp1 | Schema::Tbbo => $handler!(Mbp1Msg),
            Schema::Bbo1S | Schema::Bbo1M => $handler!(BboMsg),
            Schema::Mbp10 => $handler!(Mbp10Msg),
            Schema::Trades => $handler!(TradeMsg),
            Schema::Ohlcv1D
            | Schema::Ohlcv1H
            | Schema::Ohlcv1M
            | Schema::Ohlcv1S
            | Schema::OhlcvEod => {
                $handler!(OhlcvMsg)
            }
            Schema::Definition => $handler!(InstrumentDefMsg),
            Schema::Statistics => $handler!(StatMsg),
            Schema::Status => $handler!(StatusMsg),
            Schema::Imbalance => $handler!(ImbalanceMsg),
            Schema::Cmbp1 | Schema::Tcbbo => {
                $handler!(Cmbp1Msg)
            }
            Schema::Cbbo1S | Schema::Cbbo1M => {
                $handler!(CbboMsg)
            }
        }
    }};
}

/// Dispatches to a generic function or method based on `$schema` and optionally `$ts_out`.
///
/// # Errors
/// This macro returns an error when the generic function or method returns an error.
#[macro_export]
macro_rules! schema_dispatch {
    // generic async method
    ($schema:expr, $this:ident.$generic_method:ident($($arg:expr),*).await$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $this.$generic_method::<$r>($($arg),*).await
            }}
        }
        $crate::schema_dispatch_base!($schema, handler)
    }};
    // generic method
    ($schema:expr, $this:ident.$generic_method:ident($($arg:expr),*)$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $this.$generic_method::<$r>($($arg),*)
            }}
        }
        $crate::schema_dispatch_base!($schema, handler)
    }};
    // generic async function
    ($schema:expr, $generic_fn:ident($($arg:expr),*).await$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $generic_fn::<$r>($($arg),*).await
            }}
        }
        $crate::schema_dispatch_base!($schema, handler)
    }};
    // generic function
    ($schema:expr, $generic_fn:ident($($arg:expr),*)$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $generic_fn::<$r>($($arg),*)
            }}
        }
        $crate::schema_dispatch_base!($schema, handler)
    }};
    // generic async method
    ($schema:expr, ts_out: $ts_out:expr, $this:ident.$generic_method:ident($($arg:expr),*).await$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                if $ts_out {
                    $this.$generic_method::<$crate::WithTsOut<$r>>($($arg),*).await
                } else {
                    $this.$generic_method::<$r>($($arg),*).await
                }
            }}
        }
        $crate::schema_dispatch_base!($schema, handler)
   }};
    // generic method
    ($schema:expr, ts_out: $ts_out:expr, $this:ident.$generic_method:ident($($arg:expr),*)$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                if $ts_out {
                    $this.$generic_method::<$crate::WithTsOut<$r>>($($arg),*)
                } else {
                    $this.$generic_method::<$r>($($arg),*)
                }
            }}
        }
        $crate::schema_dispatch_base!($schema, handler)
    }};
    // generic async function
    ($schema:expr, ts_out: $ts_out:expr, $generic_fn:ident($($arg:expr),*).await$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                if $ts_out {
                    $generic_fn::<$crate::WithTsOut<$r>>($($arg),*).await
                } else {
                    $generic_fn::<$r>($($arg),*).await
                }
            }}
        }
        $crate::schema_dispatch_base!($schema, handler)
    }};
    // generic function
    ($schema:expr, ts_out: $ts_out:expr, $generic_fn:ident($($arg:expr),*)$(,)?) => {{
        macro_rules! handler {
            ($r:ty) => {{
                if $ts_out {
                    $generic_fn::<$crate::WithTsOut<$r>>($($arg),*)
                } else {
                    $generic_fn::<$r>($($arg),*)
                }
            }}
        }
        $crate::schema_dispatch_base!($schema, handler)
    }};
}

// DEPRECATED macros

/// Specializes a generic function to all record types and dispatches based on the
/// `rtype` and `ts_out`.
///
/// # Safety
/// Assumes `$rec_ref` contains a record with `ts_out` appended. If this is not the
/// case, the reading the record will read beyond the end of the record.
///
/// # Errors
/// This macro returns an error if the rtype is not recognized.
#[deprecated(since = "0.32.0", note = "Use the updated rtype_dispatch macro")]
#[macro_export]
macro_rules! rtype_ts_out_dispatch {
    ($rec_ref:expr, $ts_out:expr, $generic_fn:expr $(,$arg:expr)*) => {{
        macro_rules! maybe_ts_out {
            ($r:ty) => {{
                if $ts_out {
                    $generic_fn($rec_ref.get_unchecked::<WithTsOut<$r>>() $(, $arg)*)
                } else {
                    $generic_fn(unsafe { $rec_ref.get_unchecked::<$r>() } $(, $arg)*)
                }
            }};
        }
        $crate::rtype_dispatch_base!($rec_ref, maybe_ts_out)
    }};
}
/// Specializes a generic method to all record types and dispatches based on the
/// `rtype` and `ts_out`.
///
/// # Safety
/// Assumes `$rec_ref` contains a record with `ts_out` appended. If this is not the
/// case, the reading the record will read beyond the end of the record.
///
/// # Errors
/// This macro returns an error if the rtype is not recognized.
#[deprecated(since = "0.32.0", note = "Use the updated rtype_dispatch macro")]
#[macro_export]
macro_rules! rtype_ts_out_method_dispatch {
    ($rec_ref:expr, $ts_out:expr, $this:expr, $generic_method:ident $(,$arg:expr)*) => {{
        macro_rules! maybe_ts_out {
            ($r:ty) => {{
                if $ts_out {
                    $this.$generic_method($rec_ref.get_unchecked::<WithTsOut<$r>>() $(, $arg)*)
                } else {
                    $this.$generic_method(unsafe { $rec_ref.get_unchecked::<$r>() } $(, $arg)*)
                }
            }};
        }
        $crate::rtype_dispatch_base!($rec_ref, maybe_ts_out)
    }};
}
/// Specializes a generic async function to all record types and dispatches based
/// `rtype` and `ts_out`.
///
/// # Errors
/// This macro returns an error if the rtype is not recognized.
#[deprecated(since = "0.32.0", note = "Use the updated rtype_dispatch macro")]
#[macro_export]
macro_rules! rtype_ts_out_async_dispatch {
    ($rec_ref:expr, $ts_out:expr, $generic_fn:expr $(,$arg:expr)*) => {{
        macro_rules! maybe_ts_out {
            ($r:ty) => {{
                if $ts_out {
                    $generic_fn($rec_ref.get_unchecked::<WithTsOut<$r>>() $(, $arg)*).await
                } else {
                    $generic_fn(unsafe { $rec_ref.get_unchecked::<$r>() } $(, $arg)*).await
                }
            }};
        }
        $crate::rtype_dispatch_base!($rec_ref, maybe_ts_out)
    }};
}
/// Specializes a generic async method to all record types and dispatches based
/// `rtype` and `ts_out`.
///
/// # Errors
/// This macro returns an error if the rtype is not recognized.
#[deprecated(since = "0.32.0", note = "Use the updated rtype_dispatch macro")]
#[macro_export]
macro_rules! rtype_ts_out_async_method_dispatch {
    ($rec_ref:expr, $ts_out:expr, $this:expr, $generic_method:ident $(,$arg:expr)*) => {{
        macro_rules! maybe_ts_out {
            ($r:ty) => {{
                if $ts_out {
                    $this.$generic_method($rec_ref.get_unchecked::<WithTsOut<$r>>() $(, $arg)*).await
                } else {
                    $this.$generic_method(unsafe { $rec_ref.get_unchecked::<$r>() } $(, $arg)*).await
                }
            }};
        }
        $crate::rtype_dispatch_base!($rec_ref, maybe_ts_out)
    }};
}
/// Specializes a generic method to all record types and dispatches based `rtype`.
///
/// # Errors
/// This macro returns an error if the rtype is not recognized.
#[deprecated(since = "0.32.0", note = "Use the updated rtype_dispatch macro")]
#[macro_export]
macro_rules! rtype_method_dispatch {
    ($rec_ref:expr, $this:expr, $generic_method:ident $(,$arg:expr)*) => {{
        macro_rules! handler {
            ($r:ty) => {{
                // Safety: checks rtype before converting.
                $this.$generic_method( unsafe { $rec_ref.get_unchecked::<$r>() } $(, $arg)*)
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
}
/// Specializes a generic async function to all record types and dispatches based
/// `rtype`.
///
/// # Errors
/// This macro returns an error if the rtype is not recognized.
#[deprecated(since = "0.32.0", note = "Use the updated rtype_dispatch macro")]
#[macro_export]
macro_rules! rtype_async_dispatch {
    ($rec_ref:expr, $generic_fn:expr $(,$arg:expr)*) => {{
        macro_rules! handler {
            ($r:ty) => {{
                // Safety: checks rtype before converting.
                $generic_fn( unsafe { $rec_ref.get_unchecked::<$r>() } $(, $arg)*).await
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    }};
}
/// Specializes a generic function to all record types wrapped in
/// [`WithTsOut`](crate::record::WithTsOut) and dispatches based on the `rtype`.
///
/// # Safety
/// Assumes `$rec_ref` contains a record with `ts_out` appended. If this is not the
/// case, the reading the record will read beyond the end of the record.
///
/// # Errors
/// This macro returns an error if the rtype is not recognized.
#[deprecated(since = "0.32.0", note = "Use the updated rtype_dispatch macro")]
#[macro_export]
macro_rules! rtype_dispatch_with_ts_out {
    ($rec_ref:expr, $generic_fn:expr $(,$arg:expr)*) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $generic_fn( $rec_ref.get_unchecked::<WithTsOut<$r>>() $(, $arg)*)
            }}
        }
        $crate::rtype_dispatch_base!($rec_ref, handler)
    };
}}

/// Specializes a generic method to all record types with an associated schema.
#[deprecated(since = "0.32.0", note = "Use the updated schema_dispatch macro")]
#[macro_export]
macro_rules! schema_method_dispatch {
    ($schema:expr, $this:expr, $generic_method:ident $(,$arg:expr)*) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $this.$generic_method::<$r>($($arg),*)
            }}
        }
        $crate::schema_dispatch_base!($schema, handler)
    }};
}
/// Specializes a generic method to all record types based on the associated type for
/// `schema` and `ts_out`.
#[deprecated(since = "0.32.0", note = "Use the updated schema_dispatch macro")]
#[macro_export]
macro_rules! schema_ts_out_method_dispatch {
    ($schema:expr, $ts_out:expr, $this:expr, $generic_method:ident $(,$arg:expr)*) => {{
        macro_rules! handler {
            ($r:ty) => {{
                if $ts_out {
                    $this.$generic_method::<WithTsOut<$r>>($($arg),*)
                } else {
                    $this.$generic_method::<$r>($($arg),*)
                }
            }}
        }
        $crate::schema_dispatch_base!($schema, handler)
    }};
}
/// Specializes a generic async method to all record types with an associated
/// schema.
#[deprecated(since = "0.32.0", note = "Use the updated schema_dispatch macro")]
#[macro_export]
macro_rules! schema_async_method_dispatch {
    ($schema:expr, $this:expr, $generic_method:ident $(,$arg:expr)*) => {{
        macro_rules! handler {
            ($r:ty) => {{
                $this.$generic_method::<$r>($($arg),*).await
            }}
        }
        $crate::schema_dispatch_base!($schema, handler)
    }};
}

#[cfg(test)]
mod tests {
    use crate::{record::HasRType, rtype};

    struct Dummy {}

    #[allow(dead_code)]
    impl Dummy {
        fn on_rtype<T: HasRType>(&self) -> bool {
            T::has_rtype(0xFF)
        }

        #[allow(clippy::extra_unused_type_parameters)]
        fn on_rtype_2<T: HasRType>(&self, x: u64, y: u64) -> u64 {
            x + y
        }

        async fn do_something<T: HasRType>(&self, arg: u8) -> bool {
            T::has_rtype(arg)
        }
    }

    fn has_rtype<T: HasRType>(arg: u8) -> bool {
        T::has_rtype(arg)
    }

    #[test]
    fn test_two_args() {
        assert!(schema_dispatch!(
            Schema::Imbalance,
            has_rtype(rtype::IMBALANCE)
        ))
    }

    #[test]
    fn test_method_two_args() {
        let dummy = Dummy {};
        let ret = schema_dispatch!(Schema::Definition, dummy.on_rtype_2(5, 6));
        assert_eq!(ret, 11);
    }

    #[test]
    fn test_method_no_args() {
        let dummy = Dummy {};
        let ret = schema_dispatch!(Schema::Definition, dummy.on_rtype());
        assert!(!ret);
    }

    #[cfg(feature = "async")]
    mod r#async {
        use super::*;

        #[tokio::test]
        async fn test_self() {
            let target = Dummy {};
            let ret_true = schema_dispatch!(
                Schema::Trades,
                target.do_something(crate::enums::rtype::MBP_0).await,
            );
            let ret_false = schema_dispatch!(Schema::Trades, target.do_something(0xff).await);
            assert!(ret_true);
            assert!(!ret_false);
        }
    }
}