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
/// The item is a wrapper to make a result item more user interface friendly.
///
/// Result items represent the objects that caused a result. For example, if a
/// check failed because the bones in a character rig are not properly named,
/// then the items would contain the bones that are named incorrectly.
///
/// The item wrapper makes the use of items user interface friendly because it
/// implements item sorting and a string representation of the item.
///
/// # Examples
/// ```rust
/// # use openchecks::Item;
/// #
/// # #[derive(Debug)]
/// # struct SceneNode {
/// # name: String,
/// # }
/// #
/// # impl SceneNode {
/// # fn new<T: AsRef<str>>(name: T) -> Self {
/// # Self { name: name.as_ref().to_string() }
/// # }
/// #
/// # fn name(&self) -> &str { &self.name }
/// # }
/// #[derive(Debug)]
/// struct SceneItem {
/// // The implementation of the scene node for this example doesn't matter.
/// scene_node: SceneNode,
/// }
///
/// impl std::cmp::PartialEq<SceneItem> for SceneItem {
/// fn eq(&self, other: &SceneItem) -> bool {
/// self.scene_node.name() == other.scene_node.name()
/// }
/// }
///
/// impl std::cmp::PartialOrd<SceneItem> for SceneItem {
/// fn partial_cmp(&self, other: &SceneItem) -> Option<std::cmp::Ordering> {
/// self.scene_node.name().partial_cmp(other.scene_node.name())
/// }
/// }
///
/// impl std::fmt::Display for SceneItem {
/// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// self.scene_node.name().fmt(f)
/// }
/// }
///
/// impl Item for SceneItem {
/// type Value<'a>
/// = &'a SceneNode
/// where
/// Self: 'a;
///
/// fn value(&self) -> Self::Value<'_> {
/// &self.scene_node
/// }
/// }
///
/// let a = SceneItem{ scene_node: SceneNode::new("a") };
/// let b = SceneItem{ scene_node: SceneNode::new("b") };
///
/// assert_ne!(a, b);
/// assert!(a < b);
/// assert_eq!(&format!("{}", a), "a");
/// ```