Crate sleep_utils

Crate sleep_utils 

Source
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, Duration objects
  • Automatic zero/negative handling: no sleep for zero or negative values
  • Multiple time units: milliseconds, seconds, minutes, hours
  • Combined units: support for formats like "1m30s", "1h2m3s"
  • Platform compatibility: uses isize for 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 1 millisecond using a number
smart_sleep(1).unwrap();

// Sleep for 1 millisecond using text with units
smart_sleep("1ms").unwrap();

// Sleep for 0.001 seconds
smart_sleep("0.001s").unwrap();

// Sleep for 1 millisecond with full unit name
smart_sleep("1 millisecond").unwrap();

// Sleep using combined units
smart_sleep("1s1ms").unwrap(); // 1 second 1 millisecond

// 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_millis(1)).unwrap();

§Errors

Functions return Result<T, SleepError> and may return the following errors:

Enums§

SleepError
Sleep utilities error types
SleepInput
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