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

Allow pilota.rust_type annotation work on container type #125

Open
Millione opened this issue Mar 28, 2023 · 6 comments
Open

Allow pilota.rust_type annotation work on container type #125

Millione opened this issue Mar 28, 2023 · 6 comments

Comments

@Millione
Copy link
Member

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>,
}
@liuxin231
Copy link
Contributor

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

@PureWhiteWu
Copy link
Member

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

@liuxin231
Copy link
Contributor

liuxin231 commented Apr 17, 2024

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

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

@PureWhiteWu
Copy link
Member

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

@liuxin231
Copy link
Contributor

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

类似这种?

@Millione
Copy link
Member Author

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

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

No branches or pull requests

3 participants