Skip to content

Attach additional custom attributes to generated impl #113

Open
@guzman-raphael

Description

@guzman-raphael

I recently came across this library and so far it has been working well for the needs of our open-source project. Thank you! 🙏

In particular, the clone feature proposed in #112 (we test-drove @SLUCHABLUB's branch) got us ~90% to a working solution. The remaining ~10% we are missing is what this feature request is about.

We are looking for a way to supply and apply additional custom attributes to the generated impl blocks.

Consider the following example:

use getset::Getters;

#[derive(Getters)]
#[getset(get)]
pub struct PodJob {
    pub name: String,
}

// generates
//
// impl PodJob {
//     #[inline(always)]
//     fn name(&self) -> &String {
//         &self.name
//     }
// }

Now we'd like to expose this PodJob struct and these getter methods over a CFFI boundary. This is actually pretty straightforward with a nifty project called UniFFI. To do this, here's how we export the methods without getset (clone used since that is a better real-world example).

use uniffi;

#[derive(uniffi::Object)]
pub struct PodJob {
    pub name: String,
}

#[uniffi::export]
impl PodJob {
    fn name(&self) -> String {
        self.name.clone()
    }
}

If there was a feature that could easily allow us to automate adding custom attributes then this package could be even more applicable in reducing the needed boilerplate for such cases. Perhaps the configuration and result could look like the following:

use uniffi;
use getset::CloneGetters;

#[derive(uniffi::Object, CloneGetters)]
#[getset(get_clone, impl_attrs = "#[uniffi::export]")]
pub struct PodJob {
    pub name: String,
}

// generates
//
// #[uniffi::export]
// impl PodJob {
//     #[inline(always)]
//     fn name(&self) -> String {
//         self.name.clone()
//     }
// }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions