workflow_nw/ipc/
id.rs

1//!
2//! IPC message identifiers. Provides [`Id64`]
3//! and allows for a custom construction of IPC
4//! message ids using the [`Generator`] trait.
5//!
6
7use crate::ipc::imports::*;
8
9/// Trait representing RPC message `Id` trait constraints
10pub trait IdT:
11    Generator
12    + Debug
13    + Clone
14    + Eq
15    + Hash
16    + BorshSerialize
17    + BorshDeserialize
18    + Serialize
19    + DeserializeOwned
20    + Send
21    + Sync
22    + 'static
23{
24}
25impl<T> IdT for T where
26    T: Generator
27        + Debug
28        + Clone
29        + Eq
30        + Hash
31        + BorshSerialize
32        + BorshDeserialize
33        + Serialize
34        + DeserializeOwned
35        + Send
36        + Sync
37        + 'static
38{
39}
40
41/// `Id` generation trait. This is typically meant to be a random number
42/// generator for a cusom message `Id`, but you can also define it to use
43/// a sequential generation.
44pub trait Generator {
45    fn generate() -> Self;
46}
47
48/// IPC message id represented by a `u64` type
49#[derive(
50    Debug, Clone, Eq, PartialEq, Hash, BorshSerialize, BorshDeserialize, Serialize, Deserialize,
51)]
52pub struct Id64(u64);
53
54impl Generator for Id64 {
55    fn generate() -> Self {
56        Id64(rand::random())
57    }
58}