Trying to make code with an optional feature "pysomething". I've just now stumbled onto cfg_attr
, and it works for simple attribute macros in pyo3, but I'm having trouble with pyo3(get)
:
If I build this code with the "pysomething" feature enabled, it compiles, but, obviously, doesn't compile with the "pysomething" feature disabled.
#[cfg(feature = "pysomething")]
use pyo3::prelude::*;
#[cfg_attr(feature = "pysomething", pyclass)]
pub struct My_Struct {
#[pyo3(get, set)]
pub foo: bool,
}
If I build this code with the "pysomething" feature enabled, it doesn't compile, with the error cannot find attribute `pyo3` in this scope
, but, it does compile with the "pysomething" feature disabled.
#[cfg(feature = "pysomething")]
use pyo3::prelude::*;
#[cfg_attr(feature = "pysomething", pyclass)]
pub struct My_Struct {
#[cfg_attr(feature = "pysomething", pyo3(get, set))]
pub foo: bool,
}
I'm assuming this has something to do with the way I'm using the pyo3(get, set)
macro, or it has something to do with using macros that take arguments inside of a cfg_attr
macro.
So, um -- help? I think it's obvious what I'm trying to do.