pub enum SleepInput {
Number(isize),
Text(String),
Duration(Duration),
}Expand description
Represents different types of sleep inputs.
This enum allows the smart_sleep function to accept multiple input types
through the Into<SleepInput> trait.
§Variants
Number(isize): Numeric input interpreted as millisecondsText(String): String input that will be parsed for durationDuration(Duration): Standard duration object
Variants§
Number(isize)
Numeric input interpreted as milliseconds
Text(String)
Text input that will be parsed for duration information
Duration(Duration)
Standard duration object
Implementations§
Source§impl SleepInput
impl SleepInput
Sourcepub fn should_sleep(&self) -> bool
pub fn should_sleep(&self) -> bool
Determines whether sleep should be performed for this input.
Returns false for zero or negative numeric values, allowing
the caller to skip sleep operations when appropriate.
§Examples
use sleep_utils::SleepInput;
let positive = SleepInput::from(1);
assert!(positive.should_sleep());
let zero = SleepInput::from(0);
assert!(!zero.should_sleep());
let negative = SleepInput::from(-50);
assert!(!negative.should_sleep());Sourcepub fn to_duration(&self) -> Result<Duration>
pub fn to_duration(&self) -> Result<Duration>
Converts the input to a Duration object.
For text inputs, this will parse the string using parse_sleep_duration.
For numeric inputs, values are interpreted as milliseconds.
§Errors
Returns [SleepError::InvalidDuration] if text input cannot be parsed.
§Examples
use sleep_utils::SleepInput;
use std::time::Duration;
let input = SleepInput::from("1ms");
let duration = input.to_duration().unwrap();
assert_eq!(duration, Duration::from_millis(1));Trait Implementations§
Source§impl Clone for SleepInput
impl Clone for SleepInput
Source§fn clone(&self) -> SleepInput
fn clone(&self) -> SleepInput
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SleepInput
impl Debug for SleepInput
Source§impl From<&str> for SleepInput
impl From<&str> for SleepInput
Source§impl From<Duration> for SleepInput
impl From<Duration> for SleepInput
Source§impl From<String> for SleepInput
impl From<String> for SleepInput
Source§impl From<i32> for SleepInput
impl From<i32> for SleepInput
Auto Trait Implementations§
impl Freeze for SleepInput
impl RefUnwindSafe for SleepInput
impl Send for SleepInput
impl Sync for SleepInput
impl Unpin for SleepInput
impl UnwindSafe for SleepInput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more