Skip to main content

_etoon/
lib.rs

1pub mod toon;
2
3#[cfg(feature = "python")]
4mod py_binding {
5    use pyo3::prelude::*;
6    use pyo3::types::PyBytes;
7
8    #[pyfunction]
9    fn dumps_bytes<'py>(py: Python<'py>, json_bytes: &Bound<'py, PyBytes>) -> PyResult<String> {
10        let bytes = json_bytes.as_bytes();
11        py.detach(|| crate::toon::encode(bytes))
12            .map_err(pyo3::exceptions::PyValueError::new_err)
13    }
14
15    #[pymodule]
16    fn _etoon(m: &Bound<'_, PyModule>) -> PyResult<()> {
17        m.add_function(wrap_pyfunction!(dumps_bytes, m)?)?;
18        Ok(())
19    }
20}