aura_anim_iced/timing/
iteration.rs1use std::num::NonZeroU32;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub struct IterationCount {
6 kind: IterationCountKind,
7}
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10enum IterationCountKind {
11 Count(NonZeroU32),
12 Infinite,
13}
14
15impl IterationCount {
16 pub const ONCE: Self = Self {
18 kind: IterationCountKind::Count(NonZeroU32::MIN),
19 };
20
21 pub const INFINITE: Self = Self {
23 kind: IterationCountKind::Infinite,
24 };
25
26 #[must_use]
28 pub fn count(count: u32) -> Self {
29 let count = NonZeroU32::new(count).unwrap_or(NonZeroU32::MIN);
30
31 Self {
32 kind: IterationCountKind::Count(count),
33 }
34 }
35
36 #[must_use]
38 pub const fn infinite() -> Self {
39 Self::INFINITE
40 }
41
42 #[must_use]
44 pub const fn finite_count(self) -> Option<u32> {
45 match self.kind {
46 IterationCountKind::Count(count) => Some(count.get()),
47 IterationCountKind::Infinite => None,
48 }
49 }
50}
51
52impl Default for IterationCount {
53 fn default() -> Self {
54 Self::ONCE
55 }
56}
57
58impl From<u32> for IterationCount {
59 fn from(value: u32) -> Self {
60 Self::count(value)
61 }
62}