Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: serde Serialize and Deserialize support for repr_c::String and repr_c::Vec #208

Open
mtorromeo opened this issue Mar 4, 2024 · 0 comments

Comments

@mtorromeo
Copy link

Hi,
firstly, thanks for the great library, which is already a huge help in simplifying my ffi code!

I would like to request a feature that would let me avoid having to duplicate a lot of struct definitions.

What I have is a bunch of structs containing Strings and Vecs and deriving Serialize and Deserialize, which I also want to use in the ffi interface and right now I have to duplicate them changing every String and Vec with their repr_c counterpart and implementing a From impl to convert them. For example:

#[derive(Serialize, Deserialize)]
struct ExampleData {
  name: String,
  list: Vec<String>,
}

mod ffi {
  #[derive_ReprC]
  #[repr(C)]
  struct ExampleData {
    name: repr_c::String,
    list: repr_c::Vec<repr_c::String>,
  }

  impl From<super::ExampleData> for ExampleData {
    fn from(value: super::TestData) -> Self {
      Self {
        name: value.name.into(),
        list: repr_c::Vec::from(value.list.into_iter().map(Into::<repr_c::String>::into).collect::<Vec<repr_c::String>>()),
      }
    }
  }
}

It would be great if I could simply do this instead:

#[derive_ReprC]
#[repr(C)]
#[derive(Serialize, Deserialize)]
struct ExampleData {
  name: repr_c::String,
  list: repr_c::Vec<repr_c::String>,
}

But this is not possible right now since repr_c::String and repr_c::Vec do not implement Serialize and Deserialize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant