iliana / rust-crowbar

Wrapper to simplify writing AWS Lambda functions in Rust (using the Python execution environment)
https://docs.rs/crowbar
Apache License 2.0
197 stars 16 forks source link

Serialize return value bound #11

Closed arcnmx closed 6 years ago

arcnmx commented 7 years ago

Allow handlers to return anything that impls : serde::Serialize. This is backward-compatible with the current serde_json::Value return type, but also allows for () return types or any other serde-compatible type - the main point here is to be able to return anything that is #[derive(Serialize)].

This is an inefficient implementation, as it uses both serde_json::value::to_value and cpython_json::from_value to convert. However, this two-step conversion was necessary previously if using serde, so in many cases it's no less efficient than before! Directly converting using a function like fn to_object<S: Serialize>(py: Python, s: S) -> Result<PyObject, Error> would be ideal, but that first needs to be written.