1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
use crate::Euui;
use uuid::Uuid;
impl Euui {
/// Modifies a specific part of the internal GUID array with the provided UUID.
///
/// # Arguments
///
/// * `uuid` - The `Uuid` instance to be inserted in the specified part of the array.
/// * `part` - The index of the GUID array to update (must be between 0 and 3).
///
/// # Returns
///
/// A new instance of `Euui` with the updated GUID array.
///
/// # Panics
///
/// This function will panic if the provided `part` index is greater than 3.
pub fn with_uuid_part(&self, uuid: Uuid, part: usize) -> Self {
if part > 3 {
panic!("Index out of bounds");
}
let mut guids = self.0;
guids[part] = uuid.as_u128();
Self(guids)
}
/// Shorthand method to update the first part of the GUID array with the provided UUID.
///
/// # Arguments
///
/// * `uuid` - The `Uuid` instance to be inserted as the first part of the GUID array.
///
/// # Returns
///
/// A new instance of `Euui` with the updated first part of the GUID array.
pub fn with_first(&self, uuid: Uuid) -> Self {
self.with_uuid_part(uuid, 0)
}
/// Shorthand method to update the second part of the GUID array with the provided UUID.
///
/// # Arguments
///
/// * `uuid` - The `Uuid` instance to be inserted as the second part of the GUID array.
///
/// # Returns
///
/// A new instance of `Euui` with the updated second part of the GUID array.
pub fn with_second(&self, uuid: Uuid) -> Self {
self.with_uuid_part(uuid, 1)
}
/// Shorthand method to update the third part of the GUID array with the provided UUID.
///
/// # Arguments
///
/// * `uuid` - The `Uuid` instance to be inserted as the third part of the GUID array.
///
/// # Returns
///
/// A new instance of `Euui` with the updated third part of the GUID array.
pub fn with_third(&self, uuid: Uuid) -> Self {
self.with_uuid_part(uuid, 2)
}
/// Shorthand method to update the fourth part of the GUID array with the provided UUID.
///
/// # Arguments
///
/// * `uuid` - The `Uuid` instance to be inserted as the fourth part of the GUID array.
///
/// # Returns
///
/// A new instance of `Euui` with the updated fourth part of the GUID array.
pub fn with_fourth(&self, uuid: Uuid) -> Self {
self.with_uuid_part(uuid, 3)
}
/// Creates a new `Euui` instance from an array of 4 `Uuid` values.
///
/// # Arguments
///
/// * `uuids` - An array containing four `Uuid` instances to initialize the internal GUID array.
///
/// # Returns
///
/// A new instance of `Euui` with the GUID array populated using the provided `Uuid` values.
pub fn from_uuids(uuids: [Uuid; 4]) -> Self {
Self([
uuids[0].as_u128(),
uuids[1].as_u128(),
uuids[2].as_u128(),
uuids[3].as_u128(),
])
}
/// Generates a new `Euui` instance with an array of random `Uuid/v4` values.
///
/// # Returns
///
/// A new `Euui` instance with all four parts of the internal GUID array
/// populated using randomly generated `Uuid/v4` values.
#[cfg(feature = "random_uuid")]
pub fn random_uuids() -> Self {
Self::from_uuids([
Uuid::new_v4(),
Uuid::new_v4(),
Uuid::new_v4(),
Uuid::new_v4(),
])
}
/// Retrieves a `Uuid` instance from the internal GUID array at the specified index.
///
/// # Arguments
///
/// * `index` - The index of the GUID array to retrieve (must be between 0 and 3).
///
/// # Returns
///
/// An `Option<Uuid>` instance:
/// - `Some(Uuid)` if the `index` is within bounds and a GUID exists at that index.
/// - `None` if the `index` is out of bounds or the GUID cannot be retrieved.
pub fn uuid(&self, index: usize) -> Option<Uuid> {
self.u128(index).map(Uuid::from_u128)
}
}