format_tools/format/
test_object_without_impl.rs1use std::
15{
16 collections::HashMap,
17 hash::Hasher,
18 hash::Hash,
19 cmp::Ordering,
20 };
22
23#[ derive( Clone, Debug, PartialEq, Eq ) ]
25pub struct TestObjectWithoutImpl
26{
27 pub id : String,
28 pub created_at : i64,
29 pub file_ids : Vec< String >,
30 pub tools : Option< Vec< HashMap< String, String > > >,
31}
32
33impl Hash for TestObjectWithoutImpl
68{
69
70 fn hash< H: Hasher >( &self, state: &mut H )
71 {
72 self.id.hash( state );
73 self.created_at.hash( state );
74 self.file_ids.hash( state );
75
76 if let Some( tools ) = &self.tools
77 {
78 for tool in tools
79 {
80 for ( key, value ) in tool
81 {
82 key.hash( state );
83 value.hash( state );
84 }
85 }
86 }
87 else
88 {
89 state.write_u8( 0 );
90 }
91 }
92
93}
94
95impl PartialOrd for TestObjectWithoutImpl
96{
97
98 fn partial_cmp( &self, other: &Self ) -> Option< Ordering >
99 {
100 Some( self.cmp( other ) )
101 }
102
103}
104
105impl Ord for TestObjectWithoutImpl
106{
107
108 fn cmp( &self, other: &Self ) -> Ordering
109 {
110 self.id
111 .cmp( &other.id )
112 .then_with( | | self.created_at.cmp( &other.created_at ) )
113 .then_with( | | self.file_ids.cmp( &other.file_ids ) )
114 }
115
116}
117
118pub fn test_objects_gen() -> Vec< TestObjectWithoutImpl >
120{
121
122 vec!
123 [
124 TestObjectWithoutImpl
125 {
126 id : "1".to_string(),
127 created_at : 1627845583,
128 file_ids : vec![ "file1".to_string(), "file2".to_string() ],
129 tools : None
130 },
131 TestObjectWithoutImpl
132 {
133 id : "2".to_string(),
134 created_at : 13,
135 file_ids : vec![ "file3".to_string(), "file4\nmore details".to_string() ],
136 tools : Some
137 (
138 vec!
139 [
140 {
141 let mut map = HashMap::new();
142 map.insert( "tool1".to_string(), "value1".to_string() );
143 map
144 },
145 {
146 let mut map = HashMap::new();
147 map.insert( "tool2".to_string(), "value2".to_string() );
148 map
149 }
150 ]
151 ),
152 },
153 ]
154
155}