Skip to content

Commit

Permalink
Doc fixes and features enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
zakstucke committed Jul 8, 2024
1 parent 464b50e commit ca36549
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 23 deletions.
13 changes: 7 additions & 6 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/bitbazaar/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod macros;

pub use any::AnyErr;

/// Shorthand for a [`Result`] with a [`Report`] as the error variant
/// Shorthand for a [`Result`] with a [`error_stack::Report`] as the error variant
pub type RResult<T, C> = Result<T, error_stack::Report<C>>;

/// Easily import all useful error items. Useful to put inside a crate prelude.
Expand Down
3 changes: 3 additions & 0 deletions rust/bitbazaar/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

//! bitbazaar - An assortment of publicly available cross-language utilities useful to my projects.
// When docs auto created for docs.rs, will include features, given docs.rs uses nightly by default:
#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))]

mod prelude;

#[cfg(feature = "cli")]
Expand Down
14 changes: 7 additions & 7 deletions rust/bitbazaar/redis/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'a, 'b, 'c, ReturnType> RedisBatch<'a, 'b, 'c, ReturnType> {

/// Expire an existing key with a new/updated ttl.
///
/// https://redis.io/commands/pexpire/
/// <https://redis.io/commands/pexpire/>
pub fn expire(mut self, namespace: &str, key: &str, ttl: chrono::Duration) -> Self {
self.pipe
.pexpire(
Expand All @@ -124,7 +124,7 @@ impl<'a, 'b, 'c, ReturnType> RedisBatch<'a, 'b, 'c, ReturnType> {
}

/// Add an entry to an ordered set (auto creating the set if it doesn't exist).
/// https://redis.io/commands/zadd/
/// <https://redis.io/commands/zadd/>
///
/// Arguments:
/// - `set_namespace`: The namespace of the set.
Expand Down Expand Up @@ -161,7 +161,7 @@ impl<'a, 'b, 'c, ReturnType> RedisBatch<'a, 'b, 'c, ReturnType> {
}

/// remove an entries from an ordered set.
/// https://redis.io/commands/zrem/
/// <https://redis.io/commands/zrem/>
///
/// Arguments:
/// - `set_namespace`: The namespace of the set.
Expand Down Expand Up @@ -194,7 +194,7 @@ impl<'a, 'b, 'c, ReturnType> RedisBatch<'a, 'b, 'c, ReturnType> {
}

/// Add multiple entries at once to an ordered set (auto creating the set if it doesn't exist).
/// https://redis.io/commands/zadd/
/// <https://redis.io/commands/zadd/>
///
/// Arguments:
/// - `set_namespace`: The namespace of the set.
Expand Down Expand Up @@ -229,7 +229,7 @@ impl<'a, 'b, 'c, ReturnType> RedisBatch<'a, 'b, 'c, ReturnType> {

/// Remove entries from an ordered set by score range. (range is inclusive)
///
/// https://redis.io/commands/zremrangebyscore/
/// <https://redis.io/commands/zremrangebyscore/>
pub fn zremrangebyscore(
mut self,
set_namespace: &str,
Expand Down Expand Up @@ -443,7 +443,7 @@ pub trait RedisBatchReturningOps<'c> {
/// - `max`: The maximum score.
/// - `limit`: The maximum number of items to return.
///
/// https://redis.io/commands/zrangebyscore/
/// `https://redis.io/commands/zrangebyscore/`
fn zrangebyscore_high_to_low<Value: FromRedisValue>(
self,
set_namespace: &str,
Expand All @@ -464,7 +464,7 @@ pub trait RedisBatchReturningOps<'c> {
/// - `max`: The maximum score.
/// - `limit`: The maximum number of items to return.
///
/// https://redis.io/commands/zrangebyscore/
/// `https://redis.io/commands/zrangebyscore/`
fn zrangebyscore_low_to_high<Value: FromRedisValue>(
self,
set_namespace: &str,
Expand Down
10 changes: 5 additions & 5 deletions rust/bitbazaar/redis/temp_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl RedisTempList {
/// - Clean up expired list items
///
/// Returns:
/// RedisTempListItem<T>: The resulting item holder which can be used to further manipulate the items.
/// `RedisTempListItem<T>`: The resulting item holder which can be used to further manipulate the items.
pub async fn push<'a, T: serde::Serialize + for<'b> serde::Deserialize<'b>>(
self: &'a Arc<Self>, // Using arc to be cloning references into the list items rather than the full list object each time.
conn: &mut RedisConn<'_>,
Expand Down Expand Up @@ -419,8 +419,8 @@ impl RedisTempList {
/// - Clean up expired list items
///
/// Returns:
/// - Some(Vec<RedisTempListItem<T>>): The resulting item holders for each of the items added, these can be used to further manipulate the items.
/// - None: Something went wrong and the items weren't added correctly.
/// - `Some(Vec<RedisTempListItem<T>>)`: The resulting item holders for each of the items added, these can be used to further manipulate the items.
/// - `None`: Something went wrong and the items weren't added correctly.
pub async fn extend<'a, T: serde::Serialize + for<'b> serde::Deserialize<'b>>(
self: &'a Arc<Self>, // Using arc to be cloning references into the list items rather than the full list object each time.
conn: &mut RedisConn<'_>,
Expand All @@ -441,7 +441,7 @@ impl RedisTempList {
}
}

/// Underlying of [`RedisTempList::read_multi`], but returns the (i64: ttl, String: item key, T: item) rather than RedisTempList<T> that makes working with items easier.
/// Underlying of [`RedisTempList::read_multi`], but returns the `(i64: ttl, String: item key, T: item)` rather than `RedisTempList<T>` that makes working with items easier.
pub async fn read_multi_raw<T: serde::Serialize + for<'a> serde::Deserialize<'a>>(
&self,
conn: &mut RedisConn<'_>,
Expand Down Expand Up @@ -528,7 +528,7 @@ impl RedisTempList {
/// - Clean up expired list items
///
/// Returns:
/// - Vec<RedisTempListItem<T>: The wrapped items in the list from newest to oldest up to the provided limit (if any).
/// - `Vec<RedisTempListItem<T>`: The wrapped items in the list from newest to oldest up to the provided limit (if any).
pub async fn read_multi<T: serde::Serialize + for<'a> serde::Deserialize<'a>>(
self: &Arc<Self>, // Using arc to be cloning references into the list items rather than the full list object each time.
conn: &mut RedisConn<'_>,
Expand Down
6 changes: 3 additions & 3 deletions rust/bitbazaar/threads/batch_futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ pub enum BatchLimit {
}

/// Batch run futures but with a limiter on parents and descendants.
/// IF HIGHEST PERFORMANCE IS NEEDED AND YOU DON'T NEED DESCENDANT LIMITING, USE [`batch_futures_stream_async_cb_perf`] or just normal [`futures::StreamExt::buffer_unordered`].
/// IF HIGHEST PERFORMANCE IS NEEDED AND YOU DON'T NEED DESCENDANT LIMITING, USE [`batch_futures_flat_stream_async_cb`] or just normal [`futures::StreamExt::buffer_unordered`].
///
/// Key specialised features:
/// - Limits can be shared with descendants/parents, preventing concurrency explosion, but also internally making sure no deadlocks.
/// - Light on memory, fut_cbs only called when imminently being processed, not requiring all in memory.
/// - Despite batching, vec of results/callbacks of results are in same order as inputted (keeping finished out of order futures in buffer until they're next in line.).
/// - The future callback will only be called when the future will imminently be polled, allowing sync setup.
///
/// If you need to start processing the results before all the futures are done, use [`batch_futures_stream_async_cb`] or [`batch_futures_stream_sync_cb`].
/// If you need to start processing the results before all the futures are done, use [`batch_futures_descendants_stream_sync_cb`] or [`batch_futures_descendants_stream_async_cb`].
///
/// If neither of the above features are needed, you may as well use `buffer_unordered` (https://users.rust-lang.org/t/batch-execution-of-futures-in-the-tokio-runtime-or-max-number-of-active-futures-at-a-time/47659)
/// If neither of the above features are needed, you may as well use `buffer_unordered` <https://users.rust-lang.org/t/batch-execution-of-futures-in-the-tokio-runtime-or-max-number-of-active-futures-at-a-time/47659>
pub async fn batch_futures_descendants<R, Fut: Future<Output = R>>(
batch_limit: &BatchLimit,
fut_cbs: impl IntoIterator<Item = impl FnOnce(BatchLimit) -> Fut>,
Expand Down
2 changes: 1 addition & 1 deletion rust/bitbazaar/threads/run_cpu_intensive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::prelude::*;
/// The following link explains the distinction between normal tokio, [`tokio::task::spawn_blocking`], and rayon.
/// For most cases you think to use [`tokio::task::spawn_blocking`], but isn't actual IO like file read/write that isn't async, and actually CPU bound stuff, rayon should be used.
/// It goes without saying, if you ever want to use anything from rayon like [`rayon::iter::ParallelIterator`], it should be inside [`run_cpu_intensive`]
/// https://ryhl.io/blog/async-what-is-blocking/#the-rayon-crate
/// <https://ryhl.io/blog/async-what-is-blocking/#the-rayon-crate>
///
/// This also makes sure to maintain the active tracing span context across into the rayon block.
pub async fn run_cpu_intensive<R: Send + 'static>(
Expand Down

0 comments on commit ca36549

Please sign in to comment.