Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct Group {
}
```

You can use `rename_all` and `rename` for field naming policies. All code generated by `derive(TS)` is under `#[cfg(any(test, feature="gents"))]`, so it has zero impact on your release binary.
You can use `rename_all` and `rename` for field naming policies.

### 3. Generate TypeScript Files

Expand Down Expand Up @@ -89,7 +89,7 @@ fn gents() {

### 5. Cross-Crate Usage

If your `TS` derives are spread across multiple crates, define a feature called `gents` in each crate and use `#[cfg(feature = "gents")]` to control code generation.
If your `TS` derives are spread across multiple crates, define a feature called `gents` in each crate and use `#[cfg(feature = "gents")]` to control code generation.
See [LogiSheets example](https://github.com/proclml/LogiSheets/blob/master/crates/buildtools/src/generate.rs) for advanced multi-crate setup.

### 6. Integration with Frontend
Expand All @@ -105,8 +105,6 @@ See [LogiSheets example](https://github.com/proclml/LogiSheets/blob/master/crate
When you add a type to `FileGroup`, all of its dependencies (other structs/enums it uses) are automatically included.
- **Customizing output:**
You can control file names, field naming, and more via attributes.
- **No runtime overhead:**
All code generated by `gents` is behind `#[cfg(test)]` or `#[cfg(feature = "gents")]` and will not affect your release binary.
- **Use in CI:**
You can run the generation test in your CI pipeline to ensure TypeScript types are always up to date.

Expand Down
5 changes: 0 additions & 5 deletions derives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ fn get_impl_block(container: Container) -> proc_macro2::TokenStream {
};
if container.generics.is_empty() {
quote! {
#[cfg(any(test, feature="gents"))]
impl ::gents::TS for #ident {
#register_func
#ts_name_func
Expand All @@ -220,7 +219,6 @@ fn get_impl_block(container: Container) -> proc_macro2::TokenStream {
.map(|g| get_generic_placeholder(&ident, g));
quote! {
#(#placeholder_impls)*
#[cfg(any(test, feature="gents"))]
impl<#(#generics_ts),*>
::gents::TS for #ident<#(#generics_idents),*>{
#register_func
Expand All @@ -240,11 +238,8 @@ fn get_generic_placeholder(
);
let ts_name = format!("{}", placeholder);
quote! {
#[cfg(any(test, feature="gents"))]
#[derive(Clone)]
#[cfg(any(test, feature="gents"))]
struct #tag_ident;
#[cfg(any(test, feature="gents"))]
impl ::gents::TS for #tag_ident {
fn _register(manager: &mut ::gents::DescriptorManager, _generic_base: bool) -> usize {
let type_id = std::any::TypeId::of::<Self>();
Expand Down
4 changes: 2 additions & 2 deletions derives/src/serde_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fn get_serde_enum_impl_block(
.collect::<Vec<_>>();
quote! {
impl<#(#generic_ser_bound),*> ::gents::serde::Serialize for #ident<#(#generics),*> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where S: ::gents::serde::Serializer
{
let dummy = match self {
Expand All @@ -195,7 +195,7 @@ fn get_serde_enum_impl_block(
}

impl<'de, #(#generic_de_bound),*> ::gents::serde::Deserialize<'de> for #ident<#(#generics),*> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where D: ::gents::serde::Deserializer<'de>
{
let dummy = #dummy_ident::deserialize(deserializer)?;
Expand Down
4 changes: 0 additions & 4 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ serde = { version = "1.0", features = ["derive"] }

[dev-dependencies]
serde_json = "1.0"

[features]
default = ["gents"]
gents = []