Skip to main content

rusty_cat/
ids.rs

1use std::fmt;
2
3use uuid::Uuid;
4
5/// Task ID returned by [`crate::MeowClient::try_enqueue`].
6///
7/// Use this ID for pause/resume/cancel operations on the same task.
8#[derive(Clone, Copy, PartialEq, Eq, Hash)]
9pub struct TaskId(Uuid);
10
11impl TaskId {
12    /// Generates a random v4 task ID.
13    pub(crate) fn new_v4() -> Self {
14        Self(Uuid::new_v4())
15    }
16}
17
18impl fmt::Debug for TaskId {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        fmt::Debug::fmt(&self.0, f)
21    }
22}
23
24impl fmt::Display for TaskId {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        fmt::Display::fmt(&self.0, f)
27    }
28}
29
30/// Listener ID returned by
31/// [`crate::MeowClient::register_global_progress_listener`].
32///
33/// Use this ID to unregister the listener later.
34#[derive(Clone, Copy, PartialEq, Eq, Hash)]
35pub struct GlobalProgressListenerId(Uuid);
36
37impl GlobalProgressListenerId {
38    /// Generates a random v4 listener ID.
39    pub(crate) fn new_v4() -> Self {
40        Self(Uuid::new_v4())
41    }
42}
43
44impl fmt::Debug for GlobalProgressListenerId {
45    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46        fmt::Debug::fmt(&self.0, f)
47    }
48}