pilota icon indicating copy to clipboard operation
pilota copied to clipboard

Allow `pilota.rust_type` annotation work on container type

Open Millione opened this issue 2 years ago • 6 comments

Feature Request

Motivation

Right now in pilota, when I wrote like this:

struct A {
  1: required map<i32, string> m,
}

It will generate:

pub struct A {
  pub m: ::std::collections::HashMap<i32, ::pilota::FastStr>,
}

And there is no other way to generate code like followings as pilota.rust_type annotation cannot work on container type.

pub struct A {
  pub m: ::std::collections::HashMap<i32, String>,
}

Millione avatar Mar 28 '23 14:03 Millione

是否可以在这两种方案中选择一个解决: 1、添加配置项可以指定是否使用FastStr生成的数据类型,毕竟FastStr为了解决性能问题,可以让使用者进行取舍。 2、在faststr库中对annotation进行适配。 或者有什么巧妙的解决方法?

liuxin231 avatar Apr 16 '24 11:04 liuxin231

@liuxin231 如果你需要用 String,直接 to_string 就好了?

PureWhiteWu avatar Apr 16 '24 19:04 PureWhiteWu

@liuxin231 如果你需要用 String,直接 to_string 就好了?

@PureWhiteWu 我理解的这个问题是在生成代码时使用了FastStr,而不是std中的String,这样导致自定义添加一些注解时无法工作,不知道是不是这样?

liuxin231 avatar Apr 17 '24 08:04 liuxin231

不是,这个只是一个例子,这个 issue 要讨论的内容是说,目前我们没有一个很好的方案给 container type 里面的元素加注解。

PureWhiteWu avatar Apr 17 '24 08:04 PureWhiteWu

tonic_build::configure() .type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")

类似这种?

liuxin231 avatar Apr 17 '24 09:04 liuxin231

@liuxin231 不是的,主要还是指通过不同的注解,让它可以作用到容器里面的类型。比如 pilota.rust_type_container

Millione avatar Apr 22 '24 09:04 Millione