Skip to content

Commit

Permalink
Merge branch 'main' into ci-issues
Browse files Browse the repository at this point in the history
  • Loading branch information
escritorio-gustavo committed May 20, 2024
2 parents 4615aed + 7d28c1a commit fcf6d7c
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 198 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
- `#[serde(with = "...")]` requires the use of `#[ts(as = "...")]` or `#[ts(type = "...")]` ([#280](https://github.com/Aleph-Alpha/ts-rs/pull/280))
- Fix incompatibility with serde for `snake_case`, `kebab-case` and `SCREAMING_SNAKE_CASE` ([#298](https://github.com/Aleph-Alpha/ts-rs/pull/298))
- `#[ts(rename_all = "...")]` no longer accepts variations in the string's casing, dashes and underscores to make behavior consistent with serde ([#298](https://github.com/Aleph-Alpha/ts-rs/pull/298))
- Remove `TypeList`, and replace `TS::dependency_types`/`TS::generics` with `TS::visit_dependencies`/`TS::visit_generics`.
This finally resolves "overflow evaluating the requirement", "reached the recursion limit" errors.
Also, compile times should benefit. This is a technically breaking change for those interacting with the `TS` trait
directly. For those just using `#[derive(TS)]` and `#[ts(...)]`, nothing changes!

### Features

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ Feel free to open an issue, discuss using GitHub discussions or open a PR.
[See CONTRIBUTING.md](https://github.com/Aleph-Alpha/ts-rs/blob/main/CONTRIBUTING.md)

### MSRV
The Minimum Supported Rust Version for this crate is 1.75.0
The Minimum Supported Rust Version for this crate is 1.63.0

License: MIT
14 changes: 6 additions & 8 deletions macros/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,24 @@ impl Dependencies {

impl ToTokens for Dependencies {
fn to_tokens(&self, tokens: &mut TokenStream) {
let crate_rename = &self.crate_rename;
let lines = self.dependencies.iter();

tokens.extend(quote![{
use #crate_rename::typelist::TypeList;
()#(#lines)*
}]);
tokens.extend(quote![
#(#lines;)*
]);
}
}

impl ToTokens for Dependency {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.extend(match self {
Dependency::Transitive { crate_rename, ty } => {
quote![.extend(<#ty as #crate_rename::TS>::dependency_types())]
quote![<#ty as #crate_rename::TS>::visit_dependencies(v)]
}
Dependency::Generics { crate_rename, ty } => {
quote![.extend(<#ty as #crate_rename::TS>::generics())]
quote![<#ty as #crate_rename::TS>::visit_generics(v)]
}
Dependency::Type(ty) => quote![.push::<#ty>()],
Dependency::Type(ty) => quote![v.visit::<#ty>()],
});
}
}
16 changes: 9 additions & 7 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ impl DerivedTS {
#generics_fn
#output_path_fn

#[allow(clippy::unused_unit)]
fn dependency_types() -> impl #crate_rename::typelist::TypeList
fn visit_dependencies(v: &mut impl #crate_rename::TypeVisitor)
where
Self: 'static,
{
Expand Down Expand Up @@ -195,15 +194,18 @@ impl DerivedTS {
let generics = generics
.type_params()
.filter(|ty| !self.concrete.contains_key(&ty.ident))
.map(|TypeParam { ident, .. }| quote![.push::<#ident>().extend(<#ident as #crate_rename::TS>::generics())]);
.map(|TypeParam { ident, .. }| {
quote![
v.visit::<#ident>();
<#ident as #crate_rename::TS>::visit_generics(v);
]
});
quote! {
#[allow(clippy::unused_unit)]
fn generics() -> impl #crate_rename::typelist::TypeList
fn visit_generics(v: &mut impl #crate_rename::TypeVisitor)
where
Self: 'static,
{
use #crate_rename::typelist::TypeList;
()#(#generics)*
#(#generics)*
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion macros/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn raw_name_to_ts_field(value: String) -> String {
}

/// Parse all `#[ts(..)]` attributes from the given slice.
pub fn parse_attrs<'a, A>(attrs: &'a [Attribute]) -> Result<A>
pub(crate) fn parse_attrs<'a, A>(attrs: &'a [Attribute]) -> Result<A>
where
A: TryFrom<&'a Attribute, Error = Error> + Attr,
{
Expand Down
2 changes: 1 addition & 1 deletion ts-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = [
"web-programming",
]
readme = "../README.md"
rust-version = "1.75.0"
rust-version = "1.63.0"

[features]
chrono-impl = ["chrono"]
Expand Down
7 changes: 2 additions & 5 deletions ts-rs/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ mod recursive_export {
use std::{any::TypeId, collections::HashSet, path::Path};

use super::export_into;
use crate::{
typelist::{TypeList, TypeVisitor},
ExportError, TS,
};
use crate::{ExportError, TypeVisitor, TS};

/// Exports `T` to the file specified by the `#[ts(export_to = ..)]` attribute within the given
/// base directory.
Expand Down Expand Up @@ -85,7 +82,7 @@ mod recursive_export {
out_dir,
error: None,
};
T::dependency_types().for_each(&mut visitor);
T::visit_dependencies(&mut visitor);

if let Some(e) = visitor.error {
Err(e)
Expand Down
Loading

0 comments on commit fcf6d7c

Please sign in to comment.