Skip to content

Commit 64e1df5

Browse files
committed
TryFromBorrowedObject for &str
1 parent 3817246 commit 64e1df5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

vm/src/builtins/str.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ impl<'a> TryFromBorrowedObject<'a> for String {
4848
}
4949
}
5050

51+
impl<'a> TryFromBorrowedObject<'a> for &'a str {
52+
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &'a PyObject) -> PyResult<Self> {
53+
let pystr: &Py<PyStr> = TryFromBorrowedObject::try_from_borrowed_object(vm, obj)?;
54+
Ok(pystr.as_str())
55+
}
56+
}
57+
5158
#[pyclass(module = false, name = "str")]
5259
pub struct PyStr {
5360
bytes: Box<[u8]>,

0 commit comments

Comments
 (0)