Trait bounds #452
-
|
Hello, I would like to export a struct that includes some trait bounds, that TS doesn't support. My struct looks like this: #[derive(Clone, Debug, Deserialize, Serialize, TS)]
#[ts(export, export_to = "query.d.ts", bound = "T: TS")]
pub struct QueryObj<T: FromStr + strum::IntoEnumIterator + StrCompare + TS> {
#[serde(default)]
pub path: String,
#[serde(default)]
pub query: String,
#[serde(default = "default_limit")]
pub limit: i64,
#[serde(default)]
pub offset: i64,
#[serde(
default = "default_fields",
deserialize_with = "split_string_to_fields"
)]
#[ts(as = "String")]
pub fields: Vec<T>,
}From the compiler I get the message, that Can someone give me a hint on how to solve this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Hey! While I strongly agree with that guidance, I'd prefer if we didn't force people to follow it. There are some technical challenges, however, that make this difficult. For your struct, ts-rs will generate an |
Beta Was this translation helpful? Give feedback.
So the issue is that you need the bounds for serde? Could you remove them from the struct itself, and use
#[serde(bound)]? There are some examples for that here.