`before` not working as expected
morgante opened this issue · comments
---
level: error
---
# Use CamelCase Serialialization
We primarily use TypeScript on the other end, so all serialized structs should be in CamelCase.
```grit
language rust
`#[derive($derive)]` as $attr where {
$derive <: contains `Serialize`,
$attr <: not before `#[serde(rename_all = "camelCase")]`,
$attr += `#[serde(rename_all = "camelCase")]`
}
Basic Example
Before:
#[cfg_attr(feature = "napi", napi_derive::napi(object))]
#[derive(Debug, Clone, Serialize, PartialEq)]
pub struct FileDiff {
pub old_path: Option<String>,
pub new_path: Option<String>,
pub ranges: Vec<RangePair>,
}
Fixed:
#[cfg_attr(feature = "napi", napi_derive::napi(object))]
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct FileDiff {
pub old_path: Option<String>,
pub new_path: Option<String>,
pub ranges: Vec<RangePair>,
}
Countercase
If you need to serialize a struct in a different case, you can use the #[serde(rename_all = "camelCase")]
attribute.
#[cfg_attr(feature = "napi", napi_derive::napi(object))]
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct FileDiff {
pub oldPath: Option<String>,
pub newPath: Option<String>,
pub ranges: Vec<RangePair>,
}
#[cfg_attr(feature = "napi", napi_derive::napi(object))]
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct FileDiff {
pub oldPath: Option<String>,
pub newPath: Option<String>,
pub ranges: Vec<RangePair>,
}