Skip to content

Commit 5bea430

Browse files
committed
Add errors docs for common crate
1 parent eea9759 commit 5bea430

File tree

6 files changed

+54
-19
lines changed

6 files changed

+54
-19
lines changed

crates/common/src/actor/data_actor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#![allow(dead_code)]
1818
#![allow(unused_variables)]
1919
#![allow(unused_imports)]
20+
#![allow(clippy::missing_errors_doc)]
2021

2122
use std::{
2223
any::{Any, TypeId},

crates/common/src/cache/mod.rs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
// limitations under the License.
1414
// -------------------------------------------------------------------------------------------------
1515

16-
//! A common in-memory `Cache` for market and execution related data.
16+
//! In-memory cache for market and execution data, with optional persistent backing.
17+
//!
18+
//! Provides methods to load, query, and update cached data such as instruments, orders, and prices.
1719
18-
// Allow missing error docs for a large number of cache methods for now.
20+
// Allow missing error documentation for now
1921
#![allow(clippy::missing_errors_doc)]
2022

2123
pub mod config;
@@ -99,8 +101,11 @@ impl Default for Cache {
99101
}
100102

101103
impl Cache {
102-
/// Creates a new [`Cache`] instance.
104+
/// Creates a new [`Cache`] instance with optional configuration and database adapter.
103105
#[must_use]
106+
/// # Note
107+
///
108+
/// Uses provided `CacheConfig` or defaults, and optional `CacheDatabaseAdapter` for persistence.
104109
pub fn new(
105110
config: Option<CacheConfig>,
106111
database: Option<Box<dyn CacheDatabaseAdapter>>,
@@ -139,7 +144,7 @@ impl Cache {
139144

140145
// -- COMMANDS --------------------------------------------------------------------------------
141146

142-
/// Clears the current general cache and loads the general objects from the cache database.
147+
/// Clears and reloads general entries from the database into the cache.
143148
///
144149
/// # Errors
145150
///
@@ -157,7 +162,7 @@ impl Cache {
157162
Ok(())
158163
}
159164

160-
/// Loads all caches (currencies, instruments, synthetics, accounts, orders, positions) from the database.
165+
/// Loads all core caches (currencies, instruments, accounts, orders, positions) from the database.
161166
///
162167
/// # Errors
163168
///
@@ -177,7 +182,7 @@ impl Cache {
177182
Ok(())
178183
}
179184

180-
/// Clears the current currencies cache and loads currencies from the cache database.
185+
/// Clears and reloads the currency cache from the database.
181186
///
182187
/// # Errors
183188
///
@@ -192,7 +197,7 @@ impl Cache {
192197
Ok(())
193198
}
194199

195-
/// Clears the current instruments cache and loads instruments from the cache database.
200+
/// Clears and reloads the instrument cache from the database.
196201
///
197202
/// # Errors
198203
///
@@ -207,8 +212,7 @@ impl Cache {
207212
Ok(())
208213
}
209214

210-
/// Clears the current synthetic instruments cache and loads synthetic instruments from the cache
211-
/// database.
215+
/// Clears and reloads the synthetic instrument cache from the database.
212216
///
213217
/// # Errors
214218
///
@@ -226,7 +230,7 @@ impl Cache {
226230
Ok(())
227231
}
228232

229-
/// Clears the current accounts cache and loads accounts from the cache database.
233+
/// Clears and reloads the account cache from the database.
230234
///
231235
/// # Errors
232236
///
@@ -244,7 +248,7 @@ impl Cache {
244248
Ok(())
245249
}
246250

247-
/// Clears the current orders cache and loads orders from the cache database.
251+
/// Clears and reloads the order cache from the database.
248252
///
249253
/// # Errors
250254
///
@@ -259,7 +263,7 @@ impl Cache {
259263
Ok(())
260264
}
261265

262-
/// Clears the current positions cache and loads positions from the cache database.
266+
/// Clears and reloads the position cache from the database.
263267
///
264268
/// # Errors
265269
///
@@ -1076,10 +1080,13 @@ impl Cache {
10761080
}
10771081
}
10781082

1079-
/// Adds a general object `value` (as bytes) to the cache at the given `key`.
1083+
/// Adds a raw bytes entry to the cache under the given key.
1084+
///
1085+
/// The cache stores only raw bytes; interpretation is the caller's responsibility.
10801086
///
1081-
/// The cache is agnostic to what the bytes actually represent (and how it may be serialized),
1082-
/// which provides maximum flexibility.
1087+
/// # Errors
1088+
///
1089+
/// Returns an error if persisting the entry to the backing database fails.
10831090
pub fn add(&mut self, key: &str, value: Bytes) -> anyhow::Result<()> {
10841091
check_valid_string(key, stringify!(key)).expect(FAILED);
10851092
check_predicate_false(value.is_empty(), stringify!(value)).expect(FAILED);
@@ -1093,7 +1100,11 @@ impl Cache {
10931100
Ok(())
10941101
}
10951102

1096-
/// Adds the given order `book` to the cache.
1103+
/// Adds an `OrderBook` to the cache.
1104+
///
1105+
/// # Errors
1106+
///
1107+
/// Returns an error if persisting the order book to the backing database fails.
10971108
pub fn add_order_book(&mut self, book: OrderBook) -> anyhow::Result<()> {
10981109
log::debug!("Adding `OrderBook` {}", book.instrument_id);
10991110

@@ -1107,7 +1118,11 @@ impl Cache {
11071118
Ok(())
11081119
}
11091120

1110-
/// Adds the given `own_book` to the cache.
1121+
/// Adds an `OwnOrderBook` to the cache.
1122+
///
1123+
/// # Errors
1124+
///
1125+
/// Returns an error if persisting the own order book fails.
11111126
pub fn add_own_order_book(&mut self, own_book: OwnOrderBook) -> anyhow::Result<()> {
11121127
log::debug!("Adding `OwnOrderBook` {}", own_book.instrument_id);
11131128

crates/common/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#![deny(nonstandard_style)]
3333
#![deny(rustdoc::broken_intra_doc_links)]
3434
#![deny(missing_debug_implementations)]
35-
// #![deny(clippy::missing_errors_doc)]
35+
#![deny(clippy::missing_errors_doc)]
3636

3737
// Uncomment once we've added trivial `Debug` impls everywhere
3838
// #![warn(missing_debug_implementations)]

crates/common/src/msgbus/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ impl MessageBus {
428428
///
429429
/// # Errors
430430
///
431-
/// This function never returns an error.
431+
/// This function never returns an error (TBD).
432432
pub const fn close(&self) -> anyhow::Result<()> {
433433
// TODO: Integrate the backing database
434434
Ok(())

crates/common/src/python/logging.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ use crate::{
3535

3636
#[pymethods]
3737
impl LoggerConfig {
38+
/// Creates a [`LoggerConfig`] from a spec string.
39+
///
40+
/// # Errors
41+
///
42+
/// Returns a Python exception if the spec string is invalid.
3843
#[staticmethod]
3944
#[pyo3(name = "from_spec")]
4045
pub fn py_from_spec(spec: String) -> PyResult<Self> {
@@ -88,6 +93,11 @@ pub fn py_init_tracing() -> PyResult<()> {
8893
///
8994
/// Should only be called once during an applications run, ideally at the
9095
/// beginning of the run.
96+
/// Initializes logging via Python interface.
97+
///
98+
/// # Errors
99+
///
100+
/// Returns a Python exception if logger initialization fails.
91101
#[pyfunction]
92102
#[pyo3(name = "init_logging")]
93103
#[allow(clippy::too_many_arguments)]

crates/common/src/python/xrate.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ use ustr::Ustr;
2222

2323
use crate::xrate::get_exchange_rate;
2424

25+
/// Calculates the exchange rate between two currencies using provided bid and ask quotes.
26+
///
27+
/// # Errors
28+
///
29+
/// This function returns an error if:
30+
/// - `price_type` is equal to `Last` or `Mark` (cannot calculate from quotes).
31+
/// - `quotes_bid` or `quotes_ask` is empty.
32+
/// - `quotes_bid` and `quotes_ask` lengths are not equal.
33+
/// - The bid or ask side of a pair is missing.
2534
#[pyfunction]
2635
#[pyo3(name = "get_exchange_rate")]
2736
#[pyo3(signature = (from_currency, to_currency, price_type, quotes_bid, quotes_ask))]

0 commit comments

Comments
 (0)