Skip to content

Commit 2bc343d

Browse files
committed
Remove PyResult wrap, array.count() never fail.
1 parent d263212 commit 2bc343d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

vm/src/stdlib/array.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ macro_rules! def_array_enum {
103103
Ok(())
104104
}
105105

106-
fn count(&self, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {
106+
fn count(&self, obj: PyObjectRef, vm: &VirtualMachine) -> usize {
107107
match self {
108108
$(ArrayContentType::$n(v) => {
109-
Ok(if let Ok(val) = $t::try_into_from_object(vm, obj) {
109+
if let Ok(val) = $t::try_into_from_object(vm, obj) {
110110
v.iter().filter(|&&a| a == val).count()
111111
} else {
112112
0
113-
})
113+
}
114114
})*
115115
}
116116
}
@@ -385,13 +385,13 @@ def_array_enum!(
385385
(Double, f64, 'd'),
386386
);
387387

388-
trait TryIntoFromObject: Sized {
388+
trait ArrayElement: Sized {
389389
fn try_into_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self>;
390390
}
391391

392392
macro_rules! adapt_try_into_from_object {
393393
($(($t:ty, $f: path),)*) => {$(
394-
impl TryIntoFromObject for $t {
394+
impl ArrayElement for $t {
395395
fn try_into_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
396396
$f(vm, obj)
397397
}
@@ -490,7 +490,7 @@ impl PyArray {
490490
}
491491

492492
#[pymethod]
493-
fn count(&self, x: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {
493+
fn count(&self, x: PyObjectRef, vm: &VirtualMachine) -> usize {
494494
self.borrow_value().count(x, vm)
495495
}
496496

0 commit comments

Comments
 (0)