monarch_hyperactor/
testing.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9//! Minimal PyO3 struct for testing `@rust_struct` mixin patching.
10//!
11//! The `#[pyclass]` module is set to the Python file that defines
12//! the `@rust_struct`-decorated class so the name-validation check passes.
13
14use pyo3::prelude::*;
15
16#[pyclass(name = "TestStruct", module = "monarch._src.actor.testing")]
17pub struct PyTestStruct {
18    value: i64,
19}
20
21#[pymethods]
22impl PyTestStruct {
23    #[new]
24    fn new(value: i64) -> Self {
25        Self { value }
26    }
27
28    fn rust_method(&self) -> i64 {
29        self.value
30    }
31
32    fn shared_method(&self) -> String {
33        "from_rust".to_string()
34    }
35}
36
37#[pyfunction]
38fn _make_test_struct(value: i64) -> PyTestStruct {
39    PyTestStruct { value }
40}
41
42pub fn register_python_bindings(module: &Bound<'_, PyModule>) -> PyResult<()> {
43    module.add_class::<PyTestStruct>()?;
44    module.add_function(wrap_pyfunction!(_make_test_struct, module)?)?;
45    Ok(())
46}