-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::{ | ||
fmt::{self, Display}, | ||
num::{NonZeroU32, ParseIntError}, | ||
ops::{Deref, DerefMut}, | ||
str::FromStr, | ||
}; | ||
|
||
/// Default wait value of 1. | ||
pub const WAIT_DEFAULT: Wait = Wait(unsafe { NonZeroU32::new_unchecked(1) }); | ||
|
||
/// Represents the frame number. | ||
#[derive(Clone, Copy, Debug)] | ||
pub struct Wait(pub NonZeroU32); | ||
|
||
impl Default for Wait { | ||
fn default() -> Self { | ||
WAIT_DEFAULT | ||
} | ||
} | ||
|
||
impl Deref for Wait { | ||
type Target = NonZeroU32; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl DerefMut for Wait { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.0 | ||
} | ||
} | ||
|
||
impl Display for Wait { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
impl FromStr for Wait { | ||
type Err = ParseIntError; | ||
|
||
fn from_str(s: &str) -> Result<Wait, ParseIntError> { | ||
s.parse::<u32>() | ||
.map(|wait| NonZeroU32::new(wait).map(Self).unwrap_or(WAIT_DEFAULT)) | ||
} | ||
} |