diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e3844a41..73a0d13cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Added `TS::generics()` ([#241](https://github.com/Aleph-Alpha/ts-rs/pull/241)) - Added `TS::WithoutGenerics` ([#241](https://github.com/Aleph-Alpha/ts-rs/pull/241)) - `Result`, `Option`, `HashMap` and `Vec` had their implementations of `TS` changed ([#241](https://github.com/Aleph-Alpha/ts-rs/pull/241)) +- Removed `TS::transparent()` ([#243](https://github.com/Aleph-Alpha/ts-rs/pull/243)) ### Features diff --git a/macros/src/deps.rs b/macros/src/deps.rs index 4d096c091..da02a80fd 100644 --- a/macros/src/deps.rs +++ b/macros/src/deps.rs @@ -13,7 +13,6 @@ impl Dependencies { } /// Adds the given type. - /// If the type is transparent, then we'll get resolve the child dependencies during runtime. pub fn push(&mut self, ty: &Type) { self.0.push(quote![.push::<#ty>()]); self.0.push(quote![ diff --git a/macros/src/lib.rs b/macros/src/lib.rs index d5d4dbf81..afb24c210 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -87,10 +87,6 @@ impl DerivedTS { { #dependencies } - - fn transparent() -> bool { - false - } } #export @@ -145,7 +141,6 @@ impl DerivedTS { impl TS for #generics { type WithoutGenerics = #generics; fn name() -> String { stringify!(#generics).to_owned() } - fn transparent() -> bool { false } } )* } diff --git a/ts-rs/src/chrono.rs b/ts-rs/src/chrono.rs index e5acfd749..514d9d4c8 100644 --- a/ts-rs/src/chrono.rs +++ b/ts-rs/src/chrono.rs @@ -14,7 +14,6 @@ macro_rules! impl_dummy { type WithoutGenerics = $t; fn name() -> String { String::new() } fn inline() -> String { String::new() } - fn transparent() -> bool { false } } )*}; } @@ -33,9 +32,6 @@ impl TS for DateTime { fn inline() -> String { "string".to_owned() } - fn transparent() -> bool { - false - } } impl TS for Date { @@ -49,7 +45,4 @@ impl TS for Date { fn inline() -> String { "string".to_owned() } - fn transparent() -> bool { - false - } } diff --git a/ts-rs/src/lib.rs b/ts-rs/src/lib.rs index 2c2e0404d..f60c64bd4 100644 --- a/ts-rs/src/lib.rs +++ b/ts-rs/src/lib.rs @@ -367,12 +367,7 @@ pub trait TS { struct Visit<'a>(&'a mut Vec); impl<'a> TypeVisitor for Visit<'a> { fn visit(&mut self) { - if T::transparent() { - // the dependency `T` is "transparent", meaning that our original type depends - // on the dependencies of `T` as well. - T::dependency_types().for_each(self); - } else if let Some(dep) = Dependency::from_ty::() { - // the dependency `T` is not transparent, so we just add it to the output + if let Some(dep) = Dependency::from_ty::() { self.0.push(dep); } } @@ -382,10 +377,6 @@ pub trait TS { deps } - /// `true` if this is a transparent type, e.g tuples or a list. - /// This is used for resolving imports when using the `export!` macro. - fn transparent() -> bool; - /// Manually export this type to a file. /// The output file can be specified by annotating the type with `#[ts(export_to = ".."]`. /// By default, the filename will be derived from the types name. @@ -453,7 +444,6 @@ macro_rules! impl_primitives { type WithoutGenerics = Self; fn name() -> String { $l.to_owned() } fn inline() -> String { ::name() } - fn transparent() -> bool { false } } )*)* }; } @@ -474,7 +464,6 @@ macro_rules! impl_tuples { { ()$(.push::<$i>())* } - fn transparent() -> bool { true } } }; ( $i2:ident $(, $i:ident)* ) => { @@ -504,7 +493,6 @@ macro_rules! impl_wrapper { { ((std::marker::PhantomData::,), T::generics()) } - fn transparent() -> bool { T::transparent() } } }; } @@ -514,6 +502,7 @@ macro_rules! impl_shadow { (as $s:ty: $($impl:tt)*) => { $($impl)* { type WithoutGenerics = <$s as TS>::WithoutGenerics; + fn ident() -> String { <$s>::ident() } fn name() -> String { <$s>::name() } fn inline() -> String { <$s>::inline() } fn inline_flattened() -> String { <$s>::inline_flattened() } @@ -529,7 +518,6 @@ macro_rules! impl_shadow { { <$s>::generics() } - fn transparent() -> bool { <$s>::transparent() } } }; } @@ -554,9 +542,6 @@ impl TS for Option { { ((std::marker::PhantomData::,), T::generics()) } - fn transparent() -> bool { - T::transparent() - } } impl TS for Result { @@ -583,9 +568,6 @@ impl TS for Result { ((PhantomData::,), E::generics()), ) } - fn transparent() -> bool { - false - } } impl TS for Vec { @@ -611,9 +593,6 @@ impl TS for Vec { { ((std::marker::PhantomData::,), T::generics()) } - fn transparent() -> bool { - false - } } // Arrays longer than this limit will be emitted as Array @@ -655,10 +634,6 @@ impl TS for [T; N] { { ((std::marker::PhantomData::,), T::generics()) } - - fn transparent() -> bool { - false - } } impl TS for HashMap { @@ -690,9 +665,6 @@ impl TS for HashMap { ((PhantomData::,), V::generics()), ) } - fn transparent() -> bool { - false - } } impl TS for Range { @@ -705,32 +677,18 @@ impl TS for Range { where Self: 'static, { - ().push::() + I::dependency_types() } - fn transparent() -> bool { - true - } -} - -impl TS for RangeInclusive { - type WithoutGenerics = RangeInclusive; - fn name() -> String { - format!("{{ start: {}, end: {}, }}", I::name(), I::name()) - } - - fn dependency_types() -> impl TypeList + fn generics() -> impl TypeList where Self: 'static, { - ().push::() - } - - fn transparent() -> bool { - true + I::generics().push::() } } +impl_shadow!(as Range: impl TS for RangeInclusive); impl_shadow!(as Vec: impl TS for HashSet); impl_shadow!(as Vec: impl TS for BTreeSet); impl_shadow!(as HashMap: impl TS for BTreeMap); @@ -817,7 +775,4 @@ impl TS for Dummy { fn name() -> String { "Dummy".to_owned() } - fn transparent() -> bool { - false - } }