1use crate::nodes::traits::py::TryIntoPy;
7use pyo3::prelude::*;
8
9#[pymodule(gil_used = false)]
10#[pyo3(name = "native")]
11pub fn libcst_native(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
12 #[pyfn(m)]
13 #[pyo3(signature = (source, encoding=None))]
14 fn parse_module(source: String, encoding: Option<&str>) -> PyResult<Py<PyAny>> {
15 let m = crate::parse_module(source.as_str(), encoding)?;
16 Python::attach(|py| m.try_into_py(py))
17 }
18
19 #[pyfn(m)]
20 fn parse_expression(source: String) -> PyResult<Py<PyAny>> {
21 let expr = crate::parse_expression(source.as_str())?;
22 Python::attach(|py| expr.try_into_py(py))
23 }
24
25 #[pyfn(m)]
26 fn parse_statement(source: String) -> PyResult<Py<PyAny>> {
27 let stm = crate::parse_statement(source.as_str())?;
28 Python::attach(|py| stm.try_into_py(py))
29 }
30
31 Ok(())
32}