Skip to content

Commit 62bff17

Browse files
committed
TryFromBorrowedObject for byteslike
1 parent 4d4e39a commit 62bff17

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

vm/src/byteslike.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ impl ArgBytesLike {
7171
}
7272
}
7373

74-
impl TryFromObject for ArgBytesLike {
75-
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
76-
Self::new(vm, &obj)
74+
impl TryFromBorrowedObject for ArgBytesLike {
75+
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<Self> {
76+
Self::new(vm, obj)
7777
}
7878
}
7979

@@ -122,9 +122,9 @@ impl ArgMemoryBuffer {
122122
}
123123
}
124124

125-
impl TryFromObject for ArgMemoryBuffer {
126-
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
127-
Self::new(vm, &obj)
125+
impl TryFromBorrowedObject for ArgMemoryBuffer {
126+
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<Self> {
127+
Self::new(vm, obj)
128128
}
129129
}
130130

wasm/lib/src/convert.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use rustpython_vm::exceptions::PyBaseExceptionRef;
88
use rustpython_vm::function::FuncArgs;
99
use rustpython_vm::VirtualMachine;
1010
use rustpython_vm::{exceptions, py_serde};
11-
use rustpython_vm::{ItemProtocol, PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol};
11+
use rustpython_vm::{
12+
ItemProtocol, PyObjectRef, PyResult, PyValue, TryFromBorrowedObject, TypeProtocol,
13+
};
1214

1315
use crate::js_module;
1416
use crate::vm_class::{stored_vm_from_wasm, WASMVirtualMachine};
@@ -139,7 +141,7 @@ pub fn py_to_js(vm: &VirtualMachine, py_obj: PyObjectRef) -> JsValue {
139141
}
140142
}
141143

142-
if let Ok(bytes) = ArgBytesLike::try_from_object(vm, py_obj.clone()) {
144+
if let Ok(bytes) = ArgBytesLike::try_from_borrowed_object(vm, &py_obj) {
143145
bytes.with_ref(|bytes| unsafe {
144146
// `Uint8Array::view` is an `unsafe fn` because it provides
145147
// a direct view into the WASM linear memory; if you were to allocate

0 commit comments

Comments
 (0)