File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,20 @@ macro_rules! def_array_enum {
105
105
}
106
106
}
107
107
108
+ fn remove( & mut self , obj: PyObjectRef , vm: & VirtualMachine ) -> PyResult <( ) >{
109
+ match self {
110
+ $( ArrayContentType :: $n( v) => {
111
+ let val = $t:: try_from_object( vm, obj) ?;
112
+ if let Some ( pos) = v. iter( ) . position( |& a| a == val) {
113
+ v. remove( pos) ;
114
+ } else {
115
+ return Err ( vm. new_value_error( "array.remove(x): x not in array" . to_owned( ) ) ) ;
116
+ }
117
+ } ) *
118
+ }
119
+ Ok ( ( ) )
120
+ }
121
+
108
122
fn frombytes( & mut self , b: & [ u8 ] ) {
109
123
match self {
110
124
$( ArrayContentType :: $n( v) => {
@@ -298,6 +312,11 @@ impl PyArray {
298
312
self . borrow_value ( ) . count ( x, vm)
299
313
}
300
314
315
+ #[ pymethod]
316
+ fn remove ( & self , x : PyObjectRef , vm : & VirtualMachine ) -> PyResult < ( ) > {
317
+ self . borrow_value_mut ( ) . remove ( x, vm)
318
+ }
319
+
301
320
#[ pymethod]
302
321
fn extend ( & self , iter : PyIterable , vm : & VirtualMachine ) -> PyResult < ( ) > {
303
322
let mut array = self . borrow_value_mut ( ) ;
You can’t perform that action at this time.
0 commit comments