Skip to content

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

@mtorromeo

Description

@mtorromeo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions