Skip to main content

nautilus_model/ffi/
enums.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use std::{ffi::c_char, str::FromStr};
17
18use nautilus_core::ffi::{
19    abort_on_panic,
20    string::{cstr_as_str, str_to_cstr},
21};
22
23use crate::enums::{
24    AccountType, AggregationSource, AggressorSide, AssetClass, BarAggregation, BookAction,
25    BookType, ContingencyType, CurrencyType, InstrumentClass, InstrumentCloseType, LiquiditySide,
26    MarketStatus, MarketStatusAction, OmsType, OptionKind, OrderSide, OrderStatus, OrderType,
27    OtoTriggerMode, PositionAdjustmentType, PositionSide, PriceType, RecordFlag, TimeInForce,
28    TradingState, TrailingOffsetType, TriggerType,
29};
30
31#[unsafe(no_mangle)]
32pub extern "C" fn account_type_to_cstr(value: AccountType) -> *const c_char {
33    str_to_cstr(value.as_ref())
34}
35
36/// Returns an enum from a Python string.
37///
38/// # Safety
39///
40/// Assumes `ptr` is a valid C string pointer.
41///
42/// # Panics
43///
44/// Panics if the C string does not correspond to a valid `AccountType` variant.
45#[unsafe(no_mangle)]
46pub unsafe extern "C" fn account_type_from_cstr(ptr: *const c_char) -> AccountType {
47    abort_on_panic(|| {
48        let value = unsafe { cstr_as_str(ptr) };
49        AccountType::from_str(value)
50            .unwrap_or_else(|_| panic!("invalid `AccountType` enum string value, was '{value}'"))
51    })
52}
53
54#[unsafe(no_mangle)]
55pub extern "C" fn aggregation_source_to_cstr(value: AggregationSource) -> *const c_char {
56    str_to_cstr(value.as_ref())
57}
58
59/// Returns an enum from a Python string.
60///
61/// # Safety
62///
63/// Assumes `ptr` is a valid C string pointer.
64///
65/// # Panics
66///
67/// Panics if the C string does not correspond to a valid `AggressorSide` variant.
68#[unsafe(no_mangle)]
69pub unsafe extern "C" fn aggregation_source_from_cstr(ptr: *const c_char) -> AggregationSource {
70    abort_on_panic(|| {
71        let value = unsafe { cstr_as_str(ptr) };
72        AggregationSource::from_str(value).unwrap_or_else(|_| {
73            panic!("invalid `AggregationSource` enum string value, was '{value}'")
74        })
75    })
76}
77
78#[unsafe(no_mangle)]
79pub extern "C" fn aggressor_side_to_cstr(value: AggressorSide) -> *const c_char {
80    str_to_cstr(value.as_ref())
81}
82
83/// Returns an enum from a Python string.
84///
85/// # Safety
86///
87/// Assumes `ptr` is a valid C string pointer.
88///
89/// # Panics
90///
91/// Panics if the C string does not correspond to a valid `AggregationSource` variant.
92#[unsafe(no_mangle)]
93pub unsafe extern "C" fn aggressor_side_from_cstr(ptr: *const c_char) -> AggressorSide {
94    abort_on_panic(|| {
95        let value = unsafe { cstr_as_str(ptr) };
96        AggressorSide::from_str(value)
97            .unwrap_or_else(|_| panic!("invalid `AggressorSide` enum string value, was '{value}'"))
98    })
99}
100
101#[unsafe(no_mangle)]
102pub extern "C" fn asset_class_to_cstr(value: AssetClass) -> *const c_char {
103    str_to_cstr(value.as_ref())
104}
105
106/// Returns an enum from a Python string.
107///
108/// # Safety
109///
110/// Assumes `ptr` is a valid C string pointer.
111///
112/// # Panics
113///
114/// Panics if the C string does not correspond to a valid `AssetClass` variant.
115#[unsafe(no_mangle)]
116pub unsafe extern "C" fn asset_class_from_cstr(ptr: *const c_char) -> AssetClass {
117    abort_on_panic(|| {
118        let value = unsafe { cstr_as_str(ptr) };
119        AssetClass::from_str(value)
120            .unwrap_or_else(|_| panic!("invalid `AssetClass` enum string value, was '{value}'"))
121    })
122}
123
124#[unsafe(no_mangle)]
125pub extern "C" fn instrument_class_to_cstr(value: InstrumentClass) -> *const c_char {
126    str_to_cstr(value.as_ref())
127}
128
129/// Returns an enum from a Python string.
130///
131/// # Safety
132///
133/// Assumes `ptr` is a valid C string pointer.
134///
135/// # Panics
136///
137/// Panics if the C string does not correspond to a valid `InstrumentClass` variant.
138#[unsafe(no_mangle)]
139pub unsafe extern "C" fn instrument_class_from_cstr(ptr: *const c_char) -> InstrumentClass {
140    abort_on_panic(|| {
141        let value = unsafe { cstr_as_str(ptr) };
142        InstrumentClass::from_str(value).unwrap_or_else(|_| {
143            panic!("invalid `InstrumentClass` enum string value, was '{value}'")
144        })
145    })
146}
147
148#[unsafe(no_mangle)]
149pub extern "C" fn bar_aggregation_to_cstr(value: BarAggregation) -> *const c_char {
150    str_to_cstr(value.as_ref())
151}
152
153/// Returns an enum from a Python string.
154///
155/// # Safety
156///
157/// Assumes `ptr` is a valid C string pointer.
158///
159/// # Panics
160///
161/// Panics if the C string does not correspond to a valid `BarAggregation` variant.
162#[unsafe(no_mangle)]
163pub unsafe extern "C" fn bar_aggregation_from_cstr(ptr: *const c_char) -> BarAggregation {
164    abort_on_panic(|| {
165        let value = unsafe { cstr_as_str(ptr) };
166        BarAggregation::from_str(value)
167            .unwrap_or_else(|_| panic!("invalid `BarAggregation` enum string value, was '{value}'"))
168    })
169}
170
171#[unsafe(no_mangle)]
172pub extern "C" fn book_action_to_cstr(value: BookAction) -> *const c_char {
173    str_to_cstr(value.as_ref())
174}
175
176/// Returns an enum from a Python string.
177///
178/// # Safety
179///
180/// Assumes `ptr` is a valid C string pointer.
181///
182/// # Panics
183///
184/// Panics if the C string does not correspond to a valid `BookAction` variant.
185#[unsafe(no_mangle)]
186pub unsafe extern "C" fn book_action_from_cstr(ptr: *const c_char) -> BookAction {
187    abort_on_panic(|| {
188        let value = unsafe { cstr_as_str(ptr) };
189        BookAction::from_str(value)
190            .unwrap_or_else(|_| panic!("invalid `BookAction` enum string value, was '{value}'"))
191    })
192}
193
194#[unsafe(no_mangle)]
195pub extern "C" fn book_type_to_cstr(value: BookType) -> *const c_char {
196    str_to_cstr(value.as_ref())
197}
198
199/// Returns an enum from a Python string.
200///
201/// # Safety
202///
203/// Assumes `ptr` is a valid C string pointer.
204///
205/// # Panics
206///
207/// Panics if the C string does not correspond to a valid `BookType` variant.
208#[unsafe(no_mangle)]
209pub unsafe extern "C" fn book_type_from_cstr(ptr: *const c_char) -> BookType {
210    abort_on_panic(|| {
211        let value = unsafe { cstr_as_str(ptr) };
212        BookType::from_str(value)
213            .unwrap_or_else(|_| panic!("invalid `BookType` enum string value, was '{value}'"))
214    })
215}
216
217#[unsafe(no_mangle)]
218pub extern "C" fn contingency_type_to_cstr(value: ContingencyType) -> *const c_char {
219    str_to_cstr(value.as_ref())
220}
221
222/// Returns an enum from a Python string.
223///
224/// # Safety
225///
226/// Assumes `ptr` is a valid C string pointer.
227///
228/// # Panics
229///
230/// Panics if the C string does not correspond to a valid `ContingencyType` variant.
231#[unsafe(no_mangle)]
232pub unsafe extern "C" fn contingency_type_from_cstr(ptr: *const c_char) -> ContingencyType {
233    abort_on_panic(|| {
234        let value = unsafe { cstr_as_str(ptr) };
235        ContingencyType::from_str(value).unwrap_or_else(|_| {
236            panic!("invalid `ContingencyType` enum string value, was '{value}'")
237        })
238    })
239}
240
241#[unsafe(no_mangle)]
242pub extern "C" fn currency_type_to_cstr(value: CurrencyType) -> *const c_char {
243    str_to_cstr(value.as_ref())
244}
245
246/// Returns an enum from a Python string.
247///
248/// # Safety
249///
250/// Assumes `ptr` is a valid C string pointer.
251///
252/// # Panics
253///
254/// Panics if the C string does not correspond to a valid `CurrencyType` variant.
255#[unsafe(no_mangle)]
256pub unsafe extern "C" fn currency_type_from_cstr(ptr: *const c_char) -> CurrencyType {
257    abort_on_panic(|| {
258        let value = unsafe { cstr_as_str(ptr) };
259        CurrencyType::from_str(value)
260            .unwrap_or_else(|_| panic!("invalid `CurrencyType` enum string value, was '{value}'"))
261    })
262}
263
264/// Returns an enum from a Python string.
265///
266/// # Safety
267///
268/// Assumes `ptr` is a valid C string pointer.
269///
270/// # Panics
271///
272/// Panics if the C string does not correspond to a valid `InstrumentCloseType` variant.
273#[unsafe(no_mangle)]
274pub unsafe extern "C" fn instrument_close_type_from_cstr(
275    ptr: *const c_char,
276) -> InstrumentCloseType {
277    abort_on_panic(|| {
278        let value = unsafe { cstr_as_str(ptr) };
279        InstrumentCloseType::from_str(value).unwrap_or_else(|_| {
280            panic!("invalid `InstrumentCloseType` enum string value, was '{value}'")
281        })
282    })
283}
284
285#[unsafe(no_mangle)]
286pub extern "C" fn instrument_close_type_to_cstr(value: InstrumentCloseType) -> *const c_char {
287    str_to_cstr(value.as_ref())
288}
289
290#[unsafe(no_mangle)]
291pub extern "C" fn liquidity_side_to_cstr(value: LiquiditySide) -> *const c_char {
292    str_to_cstr(value.as_ref())
293}
294
295/// Returns an enum from a Python string.
296///
297/// # Safety
298///
299/// Assumes `ptr` is a valid C string pointer.
300///
301/// # Panics
302///
303/// Panics if the C string does not correspond to a valid `LiquiditySide` variant.
304#[unsafe(no_mangle)]
305pub unsafe extern "C" fn liquidity_side_from_cstr(ptr: *const c_char) -> LiquiditySide {
306    abort_on_panic(|| {
307        let value = unsafe { cstr_as_str(ptr) };
308        LiquiditySide::from_str(value)
309            .unwrap_or_else(|_| panic!("invalid `LiquiditySide` enum string value, was '{value}'"))
310    })
311}
312
313#[unsafe(no_mangle)]
314pub extern "C" fn market_status_to_cstr(value: MarketStatus) -> *const c_char {
315    str_to_cstr(value.as_ref())
316}
317
318/// Returns an enum from a Python string.
319///
320/// # Safety
321///
322/// Assumes `ptr` is a valid C string pointer.
323///
324/// # Panics
325///
326/// Panics if the C string does not correspond to a valid `MarketStatus` variant.
327#[unsafe(no_mangle)]
328pub unsafe extern "C" fn market_status_from_cstr(ptr: *const c_char) -> MarketStatus {
329    abort_on_panic(|| {
330        let value = unsafe { cstr_as_str(ptr) };
331        MarketStatus::from_str(value)
332            .unwrap_or_else(|_| panic!("invalid `MarketStatus` enum string value, was '{value}'"))
333    })
334}
335
336#[unsafe(no_mangle)]
337pub extern "C" fn market_status_action_to_cstr(value: MarketStatusAction) -> *const c_char {
338    str_to_cstr(value.as_ref())
339}
340
341/// Returns an enum from a Python string.
342///
343/// # Safety
344///
345/// Assumes `ptr` is a valid C string pointer.
346///
347/// # Panics
348///
349/// Panics if the C string does not correspond to a valid `MarketStatusAction` variant.
350#[unsafe(no_mangle)]
351pub unsafe extern "C" fn market_status_action_from_cstr(ptr: *const c_char) -> MarketStatusAction {
352    abort_on_panic(|| {
353        let value = unsafe { cstr_as_str(ptr) };
354        MarketStatusAction::from_str(value).unwrap_or_else(|_| {
355            panic!("invalid `MarketStatusAction` enum string value, was '{value}'")
356        })
357    })
358}
359
360#[unsafe(no_mangle)]
361pub extern "C" fn oms_type_to_cstr(value: OmsType) -> *const c_char {
362    str_to_cstr(value.as_ref())
363}
364
365/// Returns an enum from a Python string.
366///
367/// # Safety
368///
369/// Assumes `ptr` is a valid C string pointer.
370///
371/// # Panics
372///
373/// Panics if the C string does not correspond to a valid `OmsType` variant.
374#[unsafe(no_mangle)]
375pub unsafe extern "C" fn oms_type_from_cstr(ptr: *const c_char) -> OmsType {
376    abort_on_panic(|| {
377        let value = unsafe { cstr_as_str(ptr) };
378        OmsType::from_str(value)
379            .unwrap_or_else(|_| panic!("invalid `OmsType` enum string value, was '{value}'"))
380    })
381}
382
383#[unsafe(no_mangle)]
384pub extern "C" fn option_kind_to_cstr(value: OptionKind) -> *const c_char {
385    str_to_cstr(value.as_ref())
386}
387
388/// Returns an enum from a Python string.
389///
390/// # Safety
391///
392/// Assumes `ptr` is a valid C string pointer.
393///
394/// # Panics
395///
396/// Panics if the C string does not correspond to a valid `OptionKind` variant.
397#[unsafe(no_mangle)]
398pub unsafe extern "C" fn option_kind_from_cstr(ptr: *const c_char) -> OptionKind {
399    abort_on_panic(|| {
400        let value = unsafe { cstr_as_str(ptr) };
401        OptionKind::from_str(value)
402            .unwrap_or_else(|_| panic!("invalid `OptionKind` enum string value, was '{value}'"))
403    })
404}
405
406#[unsafe(no_mangle)]
407pub extern "C" fn oto_trigger_mode_to_cstr(value: OtoTriggerMode) -> *const c_char {
408    str_to_cstr(value.as_ref())
409}
410
411/// Returns an enum from a Python string.
412///
413/// # Safety
414///
415/// Assumes `ptr` is a valid C string pointer.
416///
417/// # Panics
418///
419/// Panics if the C string does not correspond to a valid `OtoTriggerMode` variant.
420#[unsafe(no_mangle)]
421pub unsafe extern "C" fn oto_trigger_mode_from_cstr(ptr: *const c_char) -> OtoTriggerMode {
422    abort_on_panic(|| {
423        let value = unsafe { cstr_as_str(ptr) };
424        OtoTriggerMode::from_str(value)
425            .unwrap_or_else(|_| panic!("invalid `OtoTriggerMode` enum string value, was '{value}'"))
426    })
427}
428
429#[unsafe(no_mangle)]
430pub extern "C" fn order_side_to_cstr(value: OrderSide) -> *const c_char {
431    str_to_cstr(value.as_ref())
432}
433
434/// Returns an enum from a Python string.
435///
436/// # Safety
437///
438/// Assumes `ptr` is a valid C string pointer.
439///
440/// # Panics
441///
442/// Panics if the C string does not correspond to a valid `OrderSide` variant.
443#[unsafe(no_mangle)]
444pub unsafe extern "C" fn order_side_from_cstr(ptr: *const c_char) -> OrderSide {
445    abort_on_panic(|| {
446        let value = unsafe { cstr_as_str(ptr) };
447        OrderSide::from_str(value)
448            .unwrap_or_else(|_| panic!("invalid `OrderSide` enum string value, was '{value}'"))
449    })
450}
451
452#[unsafe(no_mangle)]
453pub extern "C" fn order_status_to_cstr(value: OrderStatus) -> *const c_char {
454    str_to_cstr(value.as_ref())
455}
456
457/// Returns an enum from a Python string.
458///
459/// # Safety
460///
461/// Assumes `ptr` is a valid C string pointer.
462///
463/// # Panics
464///
465/// Panics if the C string does not correspond to a valid `OrderStatus` variant.
466#[unsafe(no_mangle)]
467pub unsafe extern "C" fn order_status_from_cstr(ptr: *const c_char) -> OrderStatus {
468    abort_on_panic(|| {
469        let value = unsafe { cstr_as_str(ptr) };
470        OrderStatus::from_str(value)
471            .unwrap_or_else(|_| panic!("invalid `OrderStatus` enum string value, was '{value}'"))
472    })
473}
474
475#[unsafe(no_mangle)]
476pub extern "C" fn order_type_to_cstr(value: OrderType) -> *const c_char {
477    str_to_cstr(value.as_ref())
478}
479
480/// Returns an enum from a Python string.
481///
482/// # Safety
483///
484/// Assumes `ptr` is a valid C string pointer.
485///
486/// # Panics
487///
488/// Panics if the C string does not correspond to a valid `OrderType` variant.
489#[unsafe(no_mangle)]
490pub unsafe extern "C" fn order_type_from_cstr(ptr: *const c_char) -> OrderType {
491    abort_on_panic(|| {
492        let value = unsafe { cstr_as_str(ptr) };
493        OrderType::from_str(value)
494            .unwrap_or_else(|_| panic!("invalid `OrderType` enum string value, was '{value}'"))
495    })
496}
497
498#[unsafe(no_mangle)]
499pub extern "C" fn position_side_to_cstr(value: PositionSide) -> *const c_char {
500    str_to_cstr(value.as_ref())
501}
502
503/// Returns an enum from a Python string.
504///
505/// # Safety
506///
507/// Assumes `ptr` is a valid C string pointer.
508///
509/// # Panics
510///
511/// Panics if the C string does not correspond to a valid `PositionSide` variant.
512#[unsafe(no_mangle)]
513pub unsafe extern "C" fn position_side_from_cstr(ptr: *const c_char) -> PositionSide {
514    abort_on_panic(|| {
515        let value = unsafe { cstr_as_str(ptr) };
516        PositionSide::from_str(value)
517            .unwrap_or_else(|_| panic!("invalid `PositionSide` enum string value, was '{value}'"))
518    })
519}
520
521#[unsafe(no_mangle)]
522pub extern "C" fn position_adjustment_type_to_cstr(value: PositionAdjustmentType) -> *const c_char {
523    str_to_cstr(value.as_ref())
524}
525
526/// Returns an enum from a Python string.
527///
528/// # Safety
529///
530/// Assumes `ptr` is a valid C string pointer.
531///
532/// # Panics
533///
534/// Panics if the C string does not correspond to a valid `PositionAdjustmentType` variant.
535#[unsafe(no_mangle)]
536pub unsafe extern "C" fn position_adjustment_type_from_cstr(
537    ptr: *const c_char,
538) -> PositionAdjustmentType {
539    abort_on_panic(|| {
540        let value = unsafe { cstr_as_str(ptr) };
541        PositionAdjustmentType::from_str(value).unwrap_or_else(|_| {
542            panic!("invalid `PositionAdjustmentType` enum string value, was '{value}'")
543        })
544    })
545}
546
547#[unsafe(no_mangle)]
548pub extern "C" fn price_type_to_cstr(value: PriceType) -> *const c_char {
549    str_to_cstr(value.as_ref())
550}
551
552/// Returns an enum from a Python string.
553///
554/// # Safety
555///
556/// Assumes `ptr` is a valid C string pointer.
557///
558/// # Panics
559///
560/// Panics if the C string does not correspond to a valid `PriceType` variant.
561#[unsafe(no_mangle)]
562pub unsafe extern "C" fn price_type_from_cstr(ptr: *const c_char) -> PriceType {
563    abort_on_panic(|| {
564        let value = unsafe { cstr_as_str(ptr) };
565        PriceType::from_str(value)
566            .unwrap_or_else(|_| panic!("invalid `PriceType` enum string value, was '{value}'"))
567    })
568}
569
570#[unsafe(no_mangle)]
571pub extern "C" fn record_flag_to_cstr(value: RecordFlag) -> *const c_char {
572    str_to_cstr(value.as_ref())
573}
574
575/// Returns an enum from a Python string.
576///
577/// # Safety
578///
579/// Assumes `ptr` is a valid C string pointer.
580///
581/// # Panics
582///
583/// Panics if the C string does not correspond to a valid `RecordFlag` variant.
584#[unsafe(no_mangle)]
585pub unsafe extern "C" fn record_flag_from_cstr(ptr: *const c_char) -> RecordFlag {
586    abort_on_panic(|| {
587        let value = unsafe { cstr_as_str(ptr) };
588        RecordFlag::from_str(value)
589            .unwrap_or_else(|_| panic!("invalid `RecordFlag` enum string value, was '{value}'"))
590    })
591}
592
593#[unsafe(no_mangle)]
594pub extern "C" fn time_in_force_to_cstr(value: TimeInForce) -> *const c_char {
595    str_to_cstr(value.as_ref())
596}
597
598/// Returns an enum from a Python string.
599///
600/// # Safety
601///
602/// Assumes `ptr` is a valid C string pointer.
603///
604/// # Panics
605///
606/// Panics if the C string does not correspond to a valid `TimeInForce` variant.
607#[unsafe(no_mangle)]
608pub unsafe extern "C" fn time_in_force_from_cstr(ptr: *const c_char) -> TimeInForce {
609    abort_on_panic(|| {
610        let value = unsafe { cstr_as_str(ptr) };
611        TimeInForce::from_str(value)
612            .unwrap_or_else(|_| panic!("invalid `TimeInForce` enum string value, was '{value}'"))
613    })
614}
615
616#[unsafe(no_mangle)]
617pub extern "C" fn trading_state_to_cstr(value: TradingState) -> *const c_char {
618    str_to_cstr(value.as_ref())
619}
620
621/// Returns an enum from a Python string.
622///
623/// # Safety
624///
625/// Assumes `ptr` is a valid C string pointer.
626///
627/// # Panics
628///
629/// Panics if the C string does not correspond to a valid `TradingState` variant.
630#[unsafe(no_mangle)]
631pub unsafe extern "C" fn trading_state_from_cstr(ptr: *const c_char) -> TradingState {
632    abort_on_panic(|| {
633        let value = unsafe { cstr_as_str(ptr) };
634        TradingState::from_str(value)
635            .unwrap_or_else(|_| panic!("invalid `TradingState` enum string value, was '{value}'"))
636    })
637}
638
639#[unsafe(no_mangle)]
640pub extern "C" fn trailing_offset_type_to_cstr(value: TrailingOffsetType) -> *const c_char {
641    str_to_cstr(value.as_ref())
642}
643
644/// Returns an enum from a Python string.
645///
646/// # Safety
647///
648/// Assumes `ptr` is a valid C string pointer.
649///
650/// # Panics
651///
652/// Panics if the C string does not correspond to a valid `TrailingOffsetType` variant.
653#[unsafe(no_mangle)]
654pub unsafe extern "C" fn trailing_offset_type_from_cstr(ptr: *const c_char) -> TrailingOffsetType {
655    abort_on_panic(|| {
656        let value = unsafe { cstr_as_str(ptr) };
657        TrailingOffsetType::from_str(value).unwrap_or_else(|_| {
658            panic!("invalid `TrailingOffsetType` enum string value, was '{value}'")
659        })
660    })
661}
662
663#[unsafe(no_mangle)]
664pub extern "C" fn trigger_type_to_cstr(value: TriggerType) -> *const c_char {
665    str_to_cstr(value.as_ref())
666}
667
668/// Returns an enum from a Python string.
669///
670/// # Safety
671///
672/// Assumes `ptr` is a valid C string pointer.
673///
674/// # Panics
675///
676/// Panics if the C string does not correspond to a valid `TriggerType` variant.
677#[unsafe(no_mangle)]
678pub unsafe extern "C" fn trigger_type_from_cstr(ptr: *const c_char) -> TriggerType {
679    abort_on_panic(|| {
680        let value = unsafe { cstr_as_str(ptr) };
681        TriggerType::from_str(value)
682            .unwrap_or_else(|_| panic!("invalid `TriggerType` enum string value, was '{value}'"))
683    })
684}
685
686#[cfg(test)]
687mod tests {
688    use rstest::rstest;
689
690    use super::*;
691
692    #[rstest]
693    fn test_name() {
694        assert_eq!(OrderSide::NoOrderSide.as_ref(), "NO_ORDER_SIDE");
695        assert_eq!(OrderSide::Buy.as_ref(), "BUY");
696        assert_eq!(OrderSide::Sell.as_ref(), "SELL");
697    }
698
699    #[rstest]
700    fn test_value() {
701        assert_eq!(OrderSide::NoOrderSide as u8, 0);
702        assert_eq!(OrderSide::Buy as u8, 1);
703        assert_eq!(OrderSide::Sell as u8, 2);
704    }
705}