@@ -4,70 +4,8 @@ use crate::{
44 vm:: VirtualMachine ,
55 AsObject , PyObject , PyObjectRef , PyResult ,
66} ;
7- use itertools:: Itertools ;
87use optional:: Optioned ;
9- use std:: { collections:: VecDeque , ops:: Range } ;
10-
11- pub trait ObjectSequenceOp < ' a > {
12- type Iter : ExactSizeIterator < Item = & ' a PyObjectRef > ;
13-
14- fn iter ( & ' a self ) -> Self :: Iter ;
15-
16- fn eq ( & ' a self , vm : & VirtualMachine , other : & ' a Self ) -> PyResult < bool > {
17- let lhs = self . iter ( ) ;
18- let rhs = other. iter ( ) ;
19- if lhs. len ( ) != rhs. len ( ) {
20- return Ok ( false ) ;
21- }
22- for ( a, b) in lhs. zip_eq ( rhs) {
23- if !vm. identical_or_equal ( a, b) ? {
24- return Ok ( false ) ;
25- }
26- }
27- Ok ( true )
28- }
29-
30- fn cmp ( & ' a self , vm : & VirtualMachine , other : & ' a Self , op : PyComparisonOp ) -> PyResult < bool > {
31- let less = match op {
32- PyComparisonOp :: Eq => return self . eq ( vm, other) ,
33- PyComparisonOp :: Ne => return self . eq ( vm, other) . map ( |eq| !eq) ,
34- PyComparisonOp :: Lt | PyComparisonOp :: Le => true ,
35- PyComparisonOp :: Gt | PyComparisonOp :: Ge => false ,
36- } ;
37-
38- let lhs = self . iter ( ) ;
39- let rhs = other. iter ( ) ;
40- let lhs_len = lhs. len ( ) ;
41- let rhs_len = rhs. len ( ) ;
42- for ( a, b) in lhs. zip ( rhs) {
43- let ret = if less {
44- vm. bool_seq_lt ( a, b) ?
45- } else {
46- vm. bool_seq_gt ( a, b) ?
47- } ;
48- if let Some ( v) = ret {
49- return Ok ( v) ;
50- }
51- }
52- Ok ( op. eval_ord ( lhs_len. cmp ( & rhs_len) ) )
53- }
54- }
55-
56- impl < ' a > ObjectSequenceOp < ' a > for [ PyObjectRef ] {
57- type Iter = core:: slice:: Iter < ' a , PyObjectRef > ;
58-
59- fn iter ( & ' a self ) -> Self :: Iter {
60- self . iter ( )
61- }
62- }
63-
64- impl < ' a > ObjectSequenceOp < ' a > for VecDeque < PyObjectRef > {
65- type Iter = std:: collections:: vec_deque:: Iter < ' a , PyObjectRef > ;
66-
67- fn iter ( & ' a self ) -> Self :: Iter {
68- self . iter ( )
69- }
70- }
8+ use std:: ops:: Range ;
719
7210pub trait MutObjectSequenceOp < ' a > {
7311 type Guard ;
@@ -242,7 +180,7 @@ pub trait MutObjectSequenceOp<'a> {
242180 }
243181}
244182
245- pub trait SequenceOp < T : Clone >
183+ pub trait SequenceExt < T : Clone >
246184where
247185 Self : AsRef < [ T ] > ,
248186{
@@ -256,9 +194,9 @@ where
256194 }
257195}
258196
259- impl < T : Clone > SequenceOp < T > for [ T ] { }
197+ impl < T : Clone > SequenceExt < T > for [ T ] { }
260198
261- pub trait SequenceMutOp < T : Clone >
199+ pub trait SequenceMutExt < T : Clone >
262200where
263201 Self : AsRef < [ T ] > ,
264202{
@@ -282,7 +220,7 @@ where
282220 }
283221}
284222
285- impl < T : Clone > SequenceMutOp < T > for Vec < T > {
223+ impl < T : Clone > SequenceMutExt < T > for Vec < T > {
286224 fn as_vec_mut ( & mut self ) -> & mut Vec < T > {
287225 self
288226 }
0 commit comments