1mod proxy_stream;
2mod py_element;
3mod py_stream;
4mod types;
5
6use ::wingfoil::{Node, NodeOperators};
7use py_element::*;
8use py_stream::*;
9
10use pyo3::prelude::*;
11use std::rc::Rc;
12use std::time::Duration;
13
14#[pyclass(unsendable, name = "Node")]
15#[derive(Clone)]
16struct PyNode(Rc<dyn Node>);
17
18impl PyNode {
19 fn new(node: Rc<dyn Node>) -> Self {
20 Self(node)
21 }
22}
23
24#[pymethods]
25impl PyNode {
26 fn count(&self) -> PyStream {
28 self.0.count().as_py_stream()
29 }
30}
31
32#[pyfunction]
34fn ticker(seconds: f64) -> PyNode {
35 let ticker = ::wingfoil::ticker(Duration::from_secs_f64(seconds));
36 PyNode::new(ticker)
37}
38
39#[pyfunction]
40fn constant(val: Py<PyAny>) -> PyStream {
41 let strm = ::wingfoil::constant(PyElement::new(val));
42 PyStream(strm)
43}
44
45#[pymodule]
49fn _wingfoil(module: &Bound<'_, PyModule>) -> PyResult<()> {
50 _ = env_logger::try_init();
51 module.add_function(wrap_pyfunction!(ticker, module)?)?;
52 module.add_function(wrap_pyfunction!(constant, module)?)?;
53 module.add_class::<PyNode>()?;
54 module.add_class::<PyStream>()?;
55 module.add("__version__", env!("CARGO_PKG_VERSION"))?;
56 Ok(())
57}