Expand description
A smart sleep utilities library with flexible input formats and automatic zero-value handling.
This library provides intelligent sleep functionality that supports multiple input formats and automatically handles zero and negative values without performing actual sleep.
§Features
- Multiple input formats: numbers, text,
Durationobjects - Automatic zero/negative handling: no sleep for zero or negative values
- Multiple time units: milliseconds, seconds, minutes
- Platform compatibility: uses
isizefor cross-platform support - High performance: optimized regex parsing with lazy static patterns
§Examples
Basic usage with different input formats:
use sleep_utils::smart_sleep;
use std::time::Duration;
// Sleep for 100 milliseconds using a number
smart_sleep(100).unwrap();
// Sleep for 200 milliseconds using text with units
smart_sleep("200ms").unwrap();
// Sleep for 1.5 seconds
smart_sleep("1.5s").unwrap();
// Sleep for 2 seconds with full unit name
smart_sleep("2 seconds").unwrap();
// No sleep for zero values
smart_sleep(0).unwrap();
// No sleep for negative values
smart_sleep(-50).unwrap();
// Sleep using Duration object
smart_sleep(Duration::from_secs(1)).unwrap();§Errors
Functions return Result<T, SleepError> and may return the following errors:
SleepError::InvalidDurationwhen parsing invalid duration stringsSleepError::ParseErrorwhen encountering parse errorsSleepError::NumberOutOfRangewhen numbers are out of valid range
Enums§
- Sleep
Error - Sleep utilities error types
- Sleep
Input - Represents different types of sleep inputs.
Functions§
- parse_
sleep_ duration - Parse sleep duration with support for multiple formats
- sleep
- Standard sleep function for backward compatibility with
std::thread::sleep. - smart_
sleep - Smart sleep function that supports multiple input formats.
Type Aliases§
- Result
- Result type alias for sleep-utils operations