@@ -1176,77 +1176,3 @@ impl SectorId {
1176
1176
Some ( HistorySize :: from ( expiration_history_size) )
1177
1177
}
1178
1178
}
1179
-
1180
- /// A Vec<> that enforces the invariant that it cannot be empty.
1181
- #[ derive( Debug , Clone , Encode , Decode , Eq , PartialEq ) ]
1182
- pub struct NonEmptyVec < T > ( Vec < T > ) ;
1183
-
1184
- /// Error codes for `NonEmptyVec`.
1185
- #[ derive( Debug ) ]
1186
- pub enum NonEmptyVecErr {
1187
- /// Tried to create with an empty Vec
1188
- EmptyVec ,
1189
- }
1190
-
1191
- #[ allow( clippy:: len_without_is_empty) ]
1192
- impl < T : Clone > NonEmptyVec < T > {
1193
- /// Creates the Vec.
1194
- pub fn new ( vec : Vec < T > ) -> Result < Self , NonEmptyVecErr > {
1195
- if vec. is_empty ( ) {
1196
- return Err ( NonEmptyVecErr :: EmptyVec ) ;
1197
- }
1198
-
1199
- Ok ( Self ( vec) )
1200
- }
1201
-
1202
- /// Creates the Vec with the entry.
1203
- pub fn new_with_entry ( entry : T ) -> Self {
1204
- Self ( vec ! [ entry] )
1205
- }
1206
-
1207
- /// Returns the number of entries.
1208
- pub fn len ( & self ) -> usize {
1209
- self . 0 . len ( )
1210
- }
1211
-
1212
- /// Returns the slice of the entries.
1213
- pub fn as_slice ( & self ) -> & [ T ] {
1214
- self . 0 . as_slice ( )
1215
- }
1216
-
1217
- /// Returns an iterator for the entries.
1218
- pub fn iter ( & self ) -> Box < dyn Iterator < Item = & T > + ' _ > {
1219
- Box :: new ( self . 0 . iter ( ) )
1220
- }
1221
-
1222
- /// Returns a mutable iterator for the entries.
1223
- pub fn iter_mut ( & mut self ) -> Box < dyn Iterator < Item = & mut T > + ' _ > {
1224
- Box :: new ( self . 0 . iter_mut ( ) )
1225
- }
1226
-
1227
- /// Returns the first entry.
1228
- pub fn first ( & self ) -> T {
1229
- self . 0
1230
- . first ( )
1231
- . expect ( "NonEmptyVec::first(): collection cannot be empty" )
1232
- . clone ( )
1233
- }
1234
-
1235
- /// Returns the last entry.
1236
- pub fn last ( & self ) -> T {
1237
- self . 0
1238
- . last ( )
1239
- . expect ( "NonEmptyVec::last(): collection cannot be empty" )
1240
- . clone ( )
1241
- }
1242
-
1243
- /// Adds an entry to the end.
1244
- pub fn push ( & mut self , entry : T ) {
1245
- self . 0 . push ( entry) ;
1246
- }
1247
-
1248
- /// Returns the entries in the collection.
1249
- pub fn to_vec ( self ) -> Vec < T > {
1250
- self . 0
1251
- }
1252
- }
0 commit comments