Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion vm/src/function/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::{
builtins::{PyStr, PyStrRef},
common::borrow::{BorrowedValue, BorrowedValueMut},
protocol::PyBuffer,
PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, TryFromObject, VirtualMachine,
AsObject, PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, TryFromObject,
VirtualMachine,
};

// Python/getargs.c
Expand Down Expand Up @@ -57,6 +58,10 @@ impl ArgBytesLike {
pub fn is_empty(&self) -> bool {
self.len() == 0
}

pub fn as_object(&self) -> &PyObject {
&self.0.obj
}
}

impl From<ArgBytesLike> for PyBuffer {
Expand Down Expand Up @@ -126,6 +131,15 @@ pub enum ArgStrOrBytesLike {
Str(PyStrRef),
}

impl ArgStrOrBytesLike {
pub fn as_object(&self) -> &PyObject {
match self {
Self::Buf(b) => b.as_object(),
Self::Str(s) => s.as_object(),
}
}
}

impl TryFromObject for ArgStrOrBytesLike {
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
obj.downcast()
Expand Down