rustpython_vm/convert/
to_pyobject.rs

1use crate::{builtins::PyBaseExceptionRef, PyObjectRef, PyResult, VirtualMachine};
2
3/// Implemented by any type that can be returned from a built-in Python function.
4///
5/// `ToPyObject` has a blanket implementation for any built-in object payload,
6/// and should be implemented by many primitive Rust types, allowing a built-in
7/// function to simply return a `bool` or a `usize` for example.
8pub trait ToPyObject {
9    fn to_pyobject(self, vm: &VirtualMachine) -> PyObjectRef;
10}
11
12pub trait ToPyResult {
13    fn to_pyresult(self, vm: &VirtualMachine) -> PyResult;
14}
15
16pub trait ToPyException {
17    fn to_pyexception(&self, vm: &VirtualMachine) -> PyBaseExceptionRef;
18}
19
20pub trait IntoPyException {
21    fn into_pyexception(self, vm: &VirtualMachine) -> PyBaseExceptionRef;
22}
23
24impl<T> IntoPyException for &'_ T
25where
26    T: ToPyException,
27{
28    fn into_pyexception(self, vm: &VirtualMachine) -> PyBaseExceptionRef {
29        self.to_pyexception(vm)
30    }
31}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.