Skip to content

Commit

Permalink
Merge pull request #243 from Aleph-Alpha/remove-transparent
Browse files Browse the repository at this point in the history
Remove `TS::trasparent`
  • Loading branch information
escritorio-gustavo authored Feb 29, 2024
2 parents cdaae6c + 5ebe368 commit a05169e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 64 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion macros/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down
5 changes: 0 additions & 5 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ impl DerivedTS {
{
#dependencies
}

fn transparent() -> bool {
false
}
}

#export
Expand Down Expand Up @@ -145,7 +141,6 @@ impl DerivedTS {
impl TS for #generics {
type WithoutGenerics = #generics;
fn name() -> String { stringify!(#generics).to_owned() }
fn transparent() -> bool { false }
}
)*
}
Expand Down
7 changes: 0 additions & 7 deletions ts-rs/src/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
)*};
}
Expand All @@ -33,9 +32,6 @@ impl<T: TimeZone + 'static> TS for DateTime<T> {
fn inline() -> String {
"string".to_owned()
}
fn transparent() -> bool {
false
}
}

impl<T: TimeZone + 'static> TS for Date<T> {
Expand All @@ -49,7 +45,4 @@ impl<T: TimeZone + 'static> TS for Date<T> {
fn inline() -> String {
"string".to_owned()
}
fn transparent() -> bool {
false
}
}
57 changes: 6 additions & 51 deletions ts-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,7 @@ pub trait TS {
struct Visit<'a>(&'a mut Vec<Dependency>);
impl<'a> TypeVisitor for Visit<'a> {
fn visit<T: TS + 'static + ?Sized>(&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::<T>() {
// the dependency `T` is not transparent, so we just add it to the output
if let Some(dep) = Dependency::from_ty::<T>() {
self.0.push(dep);
}
}
Expand All @@ -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.
Expand Down Expand Up @@ -453,7 +444,6 @@ macro_rules! impl_primitives {
type WithoutGenerics = Self;
fn name() -> String { $l.to_owned() }
fn inline() -> String { <Self as $crate::TS>::name() }
fn transparent() -> bool { false }
}
)*)* };
}
Expand All @@ -474,7 +464,6 @@ macro_rules! impl_tuples {
{
()$(.push::<$i>())*
}
fn transparent() -> bool { true }
}
};
( $i2:ident $(, $i:ident)* ) => {
Expand Down Expand Up @@ -504,7 +493,6 @@ macro_rules! impl_wrapper {
{
((std::marker::PhantomData::<T>,), T::generics())
}
fn transparent() -> bool { T::transparent() }
}
};
}
Expand All @@ -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() }
Expand All @@ -529,7 +518,6 @@ macro_rules! impl_shadow {
{
<$s>::generics()
}
fn transparent() -> bool { <$s>::transparent() }
}
};
}
Expand All @@ -554,9 +542,6 @@ impl<T: TS> TS for Option<T> {
{
((std::marker::PhantomData::<T>,), T::generics())
}
fn transparent() -> bool {
T::transparent()
}
}

impl<T: TS, E: TS> TS for Result<T, E> {
Expand All @@ -583,9 +568,6 @@ impl<T: TS, E: TS> TS for Result<T, E> {
((PhantomData::<E>,), E::generics()),
)
}
fn transparent() -> bool {
false
}
}

impl<T: TS> TS for Vec<T> {
Expand All @@ -611,9 +593,6 @@ impl<T: TS> TS for Vec<T> {
{
((std::marker::PhantomData::<T>,), T::generics())
}
fn transparent() -> bool {
false
}
}

// Arrays longer than this limit will be emitted as Array<T>
Expand Down Expand Up @@ -655,10 +634,6 @@ impl<T: TS, const N: usize> TS for [T; N] {
{
((std::marker::PhantomData::<T>,), T::generics())
}

fn transparent() -> bool {
false
}
}

impl<K: TS, V: TS, H> TS for HashMap<K, V, H> {
Expand Down Expand Up @@ -690,9 +665,6 @@ impl<K: TS, V: TS, H> TS for HashMap<K, V, H> {
((PhantomData::<V>,), V::generics()),
)
}
fn transparent() -> bool {
false
}
}

impl<I: TS> TS for Range<I> {
Expand All @@ -705,32 +677,18 @@ impl<I: TS> TS for Range<I> {
where
Self: 'static,
{
().push::<I>()
I::dependency_types()
}

fn transparent() -> bool {
true
}
}

impl<I: TS> TS for RangeInclusive<I> {
type WithoutGenerics = RangeInclusive<Dummy>;
fn name() -> String {
format!("{{ start: {}, end: {}, }}", I::name(), I::name())
}

fn dependency_types() -> impl TypeList
fn generics() -> impl TypeList
where
Self: 'static,
{
().push::<I>()
}

fn transparent() -> bool {
true
I::generics().push::<I>()
}
}

impl_shadow!(as Range<I>: impl<I: TS> TS for RangeInclusive<I>);
impl_shadow!(as Vec<T>: impl<T: TS, H> TS for HashSet<T, H>);
impl_shadow!(as Vec<T>: impl<T: TS> TS for BTreeSet<T>);
impl_shadow!(as HashMap<K, V>: impl<K: TS, V: TS> TS for BTreeMap<K, V>);
Expand Down Expand Up @@ -817,7 +775,4 @@ impl TS for Dummy {
fn name() -> String {
"Dummy".to_owned()
}
fn transparent() -> bool {
false
}
}

0 comments on commit a05169e

Please sign in to comment.