kpdb/types/
custom_icon_uuid.rs

1// Copyright (c) 2016-2017 Martijn Rijkeboer <mrr@sru-systems.com>
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9use uuid::Uuid;
10
11/// The identifier for a custom icon.
12#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
13pub struct CustomIconUuid(pub Uuid);
14
15impl CustomIconUuid {
16    /// Create a new random custom icon identifier.
17    pub fn new_random() -> CustomIconUuid {
18        CustomIconUuid(Uuid::new_v4())
19    }
20
21    /// Create a nil/zero custom icon identifier.
22    pub fn nil() -> CustomIconUuid {
23        CustomIconUuid(Uuid::nil())
24    }
25}
26
27impl Default for CustomIconUuid {
28    fn default() -> CustomIconUuid {
29        CustomIconUuid::nil()
30    }
31}
32
33#[cfg(test)]
34mod tests {
35
36    use super::*;
37    use uuid::Uuid;
38
39    #[test]
40    fn test_new_random_returns_random_custom_icon_uuids() {
41        let a = CustomIconUuid::new_random();
42        let b = CustomIconUuid::new_random();
43        assert!(a != b);
44    }
45
46    #[test]
47    fn test_nil_returns_nil_uuid() {
48        let expected = Uuid::nil();
49        let actual = CustomIconUuid::nil().0;
50        assert_eq!(actual, expected);
51    }
52
53    #[test]
54    fn test_default_returns_nil_custom_icon_uuid() {
55        let expected = CustomIconUuid::nil();
56        let actual = CustomIconUuid::default();
57        assert_eq!(actual, expected);
58    }
59}