Expand description
Utility functions for CHIE Protocol operations.
Modules§
- async_
utils - Async utility functions.
Structs§
- LruCache
- A simple LRU (Least Recently Used) cache.
- Retry
Config - Configuration for retry logic.
- Retry
Config Builder - Builder for RetryConfig.
Functions§
- align_
down - Align value down to the previous multiple of alignment - compile-time constant.
- align_
up - Align value up to the next multiple of alignment - compile-time constant.
- average_
u64 - Calculate average of two u64 values without overflow.
- bytes_
per_ sec_ to_ mbps - Convert bytes per second to Mbps (approximate).
- bytes_
to_ gb - Convert bytes to GB (compile-time constant).
- bytes_
to_ gb_ f64 - Convert bytes to GB as floating point (compile-time constant).
- bytes_
to_ human_ readable - Convert bytes to human-readable format (KB, MB, GB, TB).
- bytes_
to_ kb - Convert bytes to KB (compile-time constant).
- bytes_
to_ kb_ f64 - Convert bytes to KB as floating point (compile-time constant).
- bytes_
to_ mb - Convert bytes to MB (compile-time constant).
- bytes_
to_ mb_ f64 - Convert bytes to MB as floating point (compile-time constant).
- bytes_
to_ tb_ f64 - Convert bytes to TB as floating point (compile-time constant).
- calculate_
bandwidth_ gbps - Calculate bandwidth in Gbps from bytes and duration.
- calculate_
bandwidth_ mbps - Calculate bandwidth in Mbps from bytes and duration.
- calculate_
percentage - Calculate percentage with two decimal places.
- calculate_
percentage_ rounded - Calculate percentage as integer (0-100) with rounding.
- chunk_
size_ with_ overhead - Calculate chunk size with padding for encryption overhead.
- cid_
to_ path_ safe - Convert CID to path-safe format.
- clamp_
const - Clamp value to a range [min, max] - compile-time constant.
- current_
timestamp_ ms - Get current Unix timestamp in milliseconds.
- days_
to_ duration - Convert days to Duration (compile-time constant).
- div_
ceil - Ceiling division (divide and round up) - compile-time constant.
- estimate_
time_ remaining - Calculate estimated time remaining based on progress.
- exponential_
backoff - Calculate exponential backoff delay with optional jitter.
- format_
duration - Format duration as human-readable string (e.g., “2h 15m 30s”).
- format_
duration_ compact - Format duration as compact string (e.g., “2h15m”, “45s”).
- format_
number_ with_ commas - Format number with thousands separators.
- gb_
to_ bytes - Convert GB to bytes (compile-time constant).
- gb_
to_ mb - Calculate megabytes from gigabytes (compile-time constant).
- hours_
to_ duration - Convert hours to Duration (compile-time constant).
- is_
in_ range - Check if value is within range (inclusive).
- is_
power_ of_ two - Check if a number is a power of 2 - compile-time constant.
- is_
timestamp_ recent - Check if timestamp is recent (within max_age_ms).
- is_
valid_ cid_ format - Check if CID format is valid (enhanced validation).
- is_
valid_ identifier - Check if string is valid ASCII identifier (alphanumeric + underscore + hyphen).
- is_
valid_ peer_ id - Validate peer ID format (basic validation).
- kb_
to_ bytes - Convert KB to bytes (compile-time constant).
- larger_
of - Get the larger of two u64 values (same as max_const but more descriptive name).
- max_
const - Return the maximum of two values - compile-time constant.
- mb_
to_ bytes - Convert MB to bytes (compile-time constant).
- mb_
to_ kb - Calculate kilobytes from megabytes (compile-time constant).
- mbps_
to_ bytes_ per_ sec - Convert Mbps to bytes per second.
- millis_
to_ duration - Convert milliseconds to Duration (compile-time constant).
- min_
const - Return the minimum of two values - compile-time constant.
- minutes_
to_ duration - Convert minutes to Duration (compile-time constant).
- normalize_
cid - Normalize CID by removing invalid characters.
- peer_
id_ hash - Calculate hash of peer ID for consistent hashing.
- percentage_
const - Calculate percentage as integer (0-100) - compile-time constant.
- round_
down_ to_ multiple - Round down to nearest multiple (compile-time constant).
- round_
up_ to_ multiple - Round up to nearest multiple (compile-time constant).
- safe_
slice - Safe string slice that doesn’t panic on invalid indices.
- saturating_
add_ const - Saturating addition (returns u64::MAX on overflow) - compile-time constant.
- saturating_
mul_ const - Saturating multiplication (returns u64::MAX on overflow) - compile-time constant.
- saturating_
sub_ const - Saturating subtraction (returns 0 on underflow) - compile-time constant.
- secs_
to_ duration - Convert seconds to Duration (compile-time constant).
- smaller_
of - Get the smaller of two u64 values (same as min_const but more descriptive name).
- tb_
to_ bytes - Convert TB to bytes (compile-time constant).
- tb_
to_ gb - Calculate gigabytes from terabytes (compile-time constant).
- timestamp_
age - Calculate age of a timestamp in milliseconds.
- timestamp_
to_ duration - Convert Unix timestamp (milliseconds) to Duration since UNIX_EPOCH.
- timestamp_
to_ systemtime - Convert timestamp to SystemTime.
- truncate_
string - Truncate string to maximum length with ellipsis.
- truncate_
with_ ellipsis - Truncate string to max length and add ellipsis if needed.
- validate_
peer_ id - Validate peer ID format and return Result.
Type Aliases§
- Storage
Result - Shorthand for storage operation results.
- Validation
Result - Shorthand for validation results.