TryFromBorrowedObject for &str

This commit is contained in:
Jeong YunWon
2023-03-21 23:07:24 +09:00
parent aad90154e5
commit 7da7929edf

View File

@@ -48,6 +48,13 @@ impl<'a> TryFromBorrowedObject<'a> for String {
}
}
impl<'a> TryFromBorrowedObject<'a> for &'a str {
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &'a PyObject) -> PyResult<Self> {
let pystr: &Py<PyStr> = TryFromBorrowedObject::try_from_borrowed_object(vm, obj)?;
Ok(pystr.as_str())
}
}
#[pyclass(module = false, name = "str")]
pub struct PyStr {
bytes: Box<[u8]>,