mejrs / rs3cache

Tools and api for reading and interpreting the RuneScape 3 game cache.
https://mejrs.github.io/rs3cache
MIT License
29 stars 3 forks source link

Add a License #1

Closed sno2 closed 3 years ago

sno2 commented 3 years ago

Hello, do you think you could add a license because I want to use your proc macro for inserting #[pyo3(get)] into all class fields? I also need to hide the attribute under a feature by default and the bug is a big blocker. Thanks

mejrs commented 3 years ago

I am willing to do that (I should have done it long ago), but I do not think you should use it.

It relies on #[cfg_eval] to expand eagerly:

While I personally use nightly features freely as this is a toy project and I don't mind it breaking on me, this is a pretty unstable feature. Certainly not something you should be using in production.

To resolve your issue now, you can also define some getters and gate those behind a cfg. Something like this:

#[cfg(feature = "pyo3")]
#[pymethods]
impl LocationConfig {
    #[getter]
    fn id(&self) -> PyResult<u32> {
        Ok(self.id)
    }

    #[getter]
    fn name(&self) -> PyResult<Option<String>> {
        Ok(self.name.clone())
    }

    // etc..
}
mejrs commented 3 years ago

Done.

sno2 commented 3 years ago

I am willing to do that (I should have done it long ago), but I do not think you should use it.

It relies on #[cfg_eval] to expand eagerly:

While I personally use nightly features freely as this is a toy project and I don't mind it breaking on me, this is a pretty unstable feature. Certainly not something you should be using in production.

To resolve your issue now, you can also define some getters and gate those behind a cfg. Something like this:

#[cfg(feature = "pyo3")]
#[pymethods]
impl LocationConfig {
    #[getter]
    fn id(&self) -> PyResult<u32> {
        Ok(self.id)
    }

    #[getter]
    fn name(&self) -> PyResult<Option<String>> {
        Ok(self.name.clone())
    }

    // etc..
}

Thanks for the feedback and adding the license, I hadn't realized that your solution still relied on nightly. I think I'll just still with dicts for my response data in Python for now and hope for #[pyclass(dataclass)] or something of sort.

mejrs commented 3 years ago

Something like a #[pyclass(get_all)] and #[pyclass(set_all)] is something I'd like too.