[2024-12-16] Changing to mod syntax in Rust

This commit is contained in:
Andrew Conlin 2024-12-16 11:09:34 +00:00
parent 6a4e818144
commit c47dd577f5

View File

@ -1,4 +1,8 @@
use pyo3::prelude::*; use pyo3::prelude::*;
#[pymodule]
mod tictoc {
use super::*;
use std::time::Instant; use std::time::Instant;
use pyo3::exceptions::PyException; use pyo3::exceptions::PyException;
@ -15,8 +19,8 @@ struct Results {
seconds: f64, seconds: f64,
} }
#[pyclass(module = "tictoc", name = "init")] #[pyclass(name = "init")]
struct Init { pub struct Init {
time: Instant, time: Instant,
#[pyo3(get)] #[pyo3(get)]
results: Results, results: Results,
@ -60,13 +64,6 @@ impl Init {
} }
} }
} }
#[pymodule]
fn tictoc(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<Init>()?;
Ok(())
}
#[test] #[test]
fn test_new() { fn test_new() {
let init = Init::new(); let init = Init::new();
@ -90,3 +87,4 @@ fn test_toc() {
let _ = init.toc(); let _ = init.toc();
assert!(init.results.nanos > 0) assert!(init.results.nanos > 0)
} }
}