rusty_common/
lib.rs

1#![cfg_attr(test, allow(clippy::unwrap_used, clippy::assertions_on_constants))]
2#![allow(clippy::needless_range_loop)]
3
4//! Common utilities and types for the rusty trading system
5//!
6//! This crate provides shared functionality used across multiple components:
7//! - Common enums and types used throughout the system
8//! - Authentication utilities for various exchanges
9//! - HTTP/WebSocket client utilities
10//! - Common error types
11//! - Memory pools for zero-allocation operations
12//! - Rate limiting utilities
13//! - Time and timestamp utilities
14//!
15//! ## Performance Optimizations
16//!
17//! This crate enforces several mandatory performance optimizations:
18//!
19//! ### Collections (via `collections` module)
20//! - `FxHashMap`/`FxHashSet`: 2-4x faster than std HashMap for HFT use cases
21//! - `SmallVec`: Stack-allocated vectors with zero heap allocation for small sizes
22//! - Type aliases for common collection patterns (orders, price levels, etc.)
23//!
24//! ### Strings (via `SmartString`)
25//! - Stack-allocated strings up to 23 bytes (covers most order IDs, symbols)
26//! - Transparent heap fallback for longer strings
27//! - ~30% faster than String for typical HFT string operations
28//!
29//! ### Benchmarks
30//! Run `cargo bench` to see performance comparisons between:
31//! - String vs SmartString
32//! - Vec vs SmallVec
33//! - HashMap vs FxHashMap
34
35pub mod auth;
36pub mod collections;
37pub mod const_fn_candidates;
38pub mod constants;
39pub mod decimal_utils;
40/// Unified error and result types for the trading system.
41pub mod error;
42pub mod error_utils;
43pub mod http;
44pub mod json;
45pub mod memory;
46pub mod pools;
47pub mod simd_macros;
48pub mod simd_price_ops;
49pub mod strings;
50pub mod time;
51pub mod types;
52pub mod utils;
53pub mod vectorized;
54pub mod websocket;
55pub mod zero_alloc_message;
56pub mod zerocopy;
57
58#[cfg(test)]
59mod smartstring_pattern_tests;
60
61#[cfg(test)]
62mod auth_smartstring_tests;
63
64#[cfg(test)]
65mod common_smartstring_tests;
66
67// Re-export commonly used items
68pub use collections::{
69    FxHashMap, FxHashSet, SmallFeatureVec, SmallOrderVec, SmallPriceLevelVec, SmallSymbolVec,
70    SmallTradeVec, SmallVec,
71};
72pub use error::{CommonError, Result};
73pub use error_utils::{AnyhowErrorExt, ErrorMessages};
74pub use memory::{
75    HftBufferHandle,
76    HftBufferPool,
77    // HFT-specific object pools
78    HftPoolManager,
79    OrderHandle,
80    OrderPool,
81    PooledOrder,
82    PooledTrade,
83    TradeHandle,
84    TradePool,
85    TradingPoolManager,
86    get_global_trading_pools,
87    global_hft_pools,
88    with_hft_pools,
89    with_thread_local_pools,
90};
91pub use pools::{
92    GenericPool, OrderPoolFactory, OrderPoolTemplate, PoolFactory, PoolStats,
93    borrow_from_global_pool, global_pool_stats, return_to_global_pool, set_global_order_pool,
94    with_global_order_pool,
95};
96pub use simd_price_ops::{SimdPriceCalculator, simd_price_impact, simd_spreads, simd_vwap};
97// MANDATORY: Use SmartString instead of String for short strings (< 24 bytes)
98// This includes: order IDs, symbols, exchange names, currency codes
99pub use smartstring::alias::String as SmartString;
100pub use strings::{ClientOrderId, CurrencyCode, ExchangeName, OrderId, TradeId};
101pub use time::{get_timestamp_ms, get_timestamp_ns_result};
102pub use types::{Exchange, Symbol};
103pub use utils::id_generation;
104pub use vectorized::{AlignedBuffer32, AlignedBuffer64, LegacyAlignedBuffer};
105pub use zero_alloc_message::{
106    MessageType, ZeroAllocMarketData, ZeroAllocMessageProcessor, ZeroAllocOrderUpdate,
107};
108pub use zerocopy::{
109    // JSON utilities
110    BorrowedValueExt,
111    // String utilities
112    BufferedStringOps,
113    ExchangeJsonZeroCopy,
114    // Buffer management
115    JsonBufferManager,
116    UnifiedBufferManager,
117    // Statistics
118    UnifiedBufferStats,
119    UnifiedStringUtils,
120    WebSocketJsonZeroCopy,
121    ZeroCopyBufferManager,
122    // General utilities
123    ZeroCopyCollections,
124    ZeroCopyJson,
125    ZeroCopyMessage,
126    ZeroCopySlice,
127    ZeroCopyStringUtils,
128    with_buffer_manager,
129    with_json_buffer_manager,
130    with_unified_buffer_manager,
131};