@@ -293,6 +293,64 @@ pub struct PyNumberSlots {
293
293
pub inplace_matrix_multiply : AtomicCell < Option < PyNumberBinaryFunc > > ,
294
294
}
295
295
296
+ impl From < & PyNumberMethods > for PyNumberSlots {
297
+ fn from ( value : & PyNumberMethods ) -> Self {
298
+ // right_* functions will use the same left function as PyNumberMethods
299
+ // allows both f(self, other) and f(other, self)
300
+ Self {
301
+ add : AtomicCell :: new ( value. add ) ,
302
+ subtract : AtomicCell :: new ( value. subtract ) ,
303
+ multiply : AtomicCell :: new ( value. multiply ) ,
304
+ remainder : AtomicCell :: new ( value. remainder ) ,
305
+ divmod : AtomicCell :: new ( value. divmod ) ,
306
+ power : AtomicCell :: new ( value. power ) ,
307
+ negative : AtomicCell :: new ( value. negative ) ,
308
+ positive : AtomicCell :: new ( value. positive ) ,
309
+ absolute : AtomicCell :: new ( value. absolute ) ,
310
+ boolean : AtomicCell :: new ( value. boolean ) ,
311
+ invert : AtomicCell :: new ( value. invert ) ,
312
+ lshift : AtomicCell :: new ( value. lshift ) ,
313
+ rshift : AtomicCell :: new ( value. rshift ) ,
314
+ and : AtomicCell :: new ( value. and ) ,
315
+ xor : AtomicCell :: new ( value. xor ) ,
316
+ or : AtomicCell :: new ( value. or ) ,
317
+ int : AtomicCell :: new ( value. int ) ,
318
+ float : AtomicCell :: new ( value. float ) ,
319
+ right_add : AtomicCell :: new ( value. add ) ,
320
+ right_subtract : AtomicCell :: new ( value. subtract ) ,
321
+ right_multiply : AtomicCell :: new ( value. multiply ) ,
322
+ right_remainder : AtomicCell :: new ( value. remainder ) ,
323
+ right_divmod : AtomicCell :: new ( value. divmod ) ,
324
+ right_power : AtomicCell :: new ( value. power ) ,
325
+ right_lshift : AtomicCell :: new ( value. lshift ) ,
326
+ right_rshift : AtomicCell :: new ( value. rshift ) ,
327
+ right_and : AtomicCell :: new ( value. and ) ,
328
+ right_xor : AtomicCell :: new ( value. xor ) ,
329
+ right_or : AtomicCell :: new ( value. or ) ,
330
+ inplace_add : AtomicCell :: new ( value. inplace_add ) ,
331
+ inplace_subtract : AtomicCell :: new ( value. inplace_subtract ) ,
332
+ inplace_multiply : AtomicCell :: new ( value. inplace_multiply ) ,
333
+ inplace_remainder : AtomicCell :: new ( value. inplace_remainder ) ,
334
+ inplace_power : AtomicCell :: new ( value. inplace_power ) ,
335
+ inplace_lshift : AtomicCell :: new ( value. inplace_lshift ) ,
336
+ inplace_rshift : AtomicCell :: new ( value. inplace_rshift ) ,
337
+ inplace_and : AtomicCell :: new ( value. inplace_and ) ,
338
+ inplace_xor : AtomicCell :: new ( value. inplace_xor ) ,
339
+ inplace_or : AtomicCell :: new ( value. inplace_or ) ,
340
+ floor_divide : AtomicCell :: new ( value. floor_divide ) ,
341
+ true_divide : AtomicCell :: new ( value. true_divide ) ,
342
+ right_floor_divide : AtomicCell :: new ( value. floor_divide ) ,
343
+ right_true_divide : AtomicCell :: new ( value. true_divide ) ,
344
+ inplace_floor_divide : AtomicCell :: new ( value. inplace_floor_divide ) ,
345
+ inplace_true_divide : AtomicCell :: new ( value. inplace_true_divide ) ,
346
+ index : AtomicCell :: new ( value. index ) ,
347
+ matrix_multiply : AtomicCell :: new ( value. matrix_multiply ) ,
348
+ right_matrix_multiply : AtomicCell :: new ( value. matrix_multiply ) ,
349
+ inplace_matrix_multiply : AtomicCell :: new ( value. inplace_matrix_multiply ) ,
350
+ }
351
+ }
352
+ }
353
+
296
354
impl PyNumberSlots {
297
355
pub fn left_binary_op ( & self , op_slot : PyNumberBinaryOp ) -> Option < PyNumberBinaryFunc > {
298
356
use PyNumberBinaryOp :: * ;
0 commit comments