File: test_field_cfg.rs

package info (click to toggle)
rust-pyo3 0.22.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 3,420 kB
  • sloc: makefile: 58; python: 39; sh: 1
file content (29 lines) | stat: -rw-r--r-- 634 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#![cfg(feature = "macros")]

use pyo3::prelude::*;

#[pyclass]
struct CfgClass {
    #[pyo3(get, set)]
    #[cfg(any())]
    pub a: u32,
    #[pyo3(get, set)]
    // This is always true
    #[cfg(any(
        target_family = "unix",
        target_family = "windows",
        target_family = "wasm"
    ))]
    pub b: u32,
}

#[test]
fn test_cfg() {
    Python::with_gil(|py| {
        let cfg = CfgClass { b: 3 };
        let py_cfg = Py::new(py, cfg).unwrap();
        assert!(py_cfg.bind(py).getattr("a").is_err());
        let b: u32 = py_cfg.bind(py).getattr("b").unwrap().extract().unwrap();
        assert_eq!(b, 3);
    });
}