1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! 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:
//!
//! - [`SleepError::InvalidDuration`] when parsing invalid duration strings
//! - [`SleepError::ParseError`] when encountering parse errors
//! - [`SleepError::NumberOutOfRange`] when numbers are out of valid range
use Duration;
pub use parse_sleep_duration;
pub use ;
pub use ;
/// Standard sleep function for backward compatibility with `std::thread::sleep`.
///
/// This function provides a simple wrapper around `std::thread::sleep` that returns
/// a [`Result`] for consistency with other functions in this crate.
///
/// # Examples
///
/// ```
/// use sleep_utils::sleep;
/// use std::time::Duration;
///
/// // Sleep for 1 millisecond
/// sleep(Duration::from_millis(1)).unwrap();
/// ```
///
/// # Notes
///
/// Unlike [`smart_sleep`], this function does not support multiple input formats
/// and will always sleep for the provided duration, even if it's zero.