mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
* perf(rust): use pythonize for bridge serialization * perf(rust): benchmark serialization payload sizes * refactor(rust): remove mutable benchmark state
20 lines
535 B
Rust
20 lines
535 B
Rust
use pyo3::exceptions::PyValueError;
|
|
use pyo3::prelude::*;
|
|
use serde::Serialize;
|
|
use serde::de::DeserializeOwned;
|
|
|
|
pub fn from_py<T>(value: &Bound<'_, PyAny>) -> PyResult<T>
|
|
where
|
|
T: DeserializeOwned,
|
|
{
|
|
pythonize::depythonize(value).map_err(|error| PyValueError::new_err(error.to_string()))
|
|
}
|
|
|
|
pub fn to_py<T>(py: Python<'_>, value: &T) -> PyResult<Py<PyAny>>
|
|
where
|
|
T: Serialize + ?Sized,
|
|
{
|
|
pythonize::pythonize(py, value)
|
|
.map(Bound::unbind)
|
|
.map_err(|error| PyValueError::new_err(error.to_string()))
|
|
}
|