-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove TS::trasparent
#243
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
} | ||
|
@@ -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 { <Self as $crate::TS>::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>,), T::generics()) | ||
} | ||
fn transparent() -> bool { T::transparent() } | ||
} | ||
}; | ||
} | ||
|
@@ -529,7 +517,6 @@ macro_rules! impl_shadow { | |
{ | ||
<$s>::generics() | ||
} | ||
fn transparent() -> bool { <$s>::transparent() } | ||
} | ||
}; | ||
} | ||
|
@@ -554,9 +541,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> { | ||
|
@@ -583,9 +567,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> { | ||
|
@@ -611,9 +592,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> | ||
|
@@ -655,10 +633,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> { | ||
|
@@ -690,9 +664,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> { | ||
|
@@ -705,11 +676,15 @@ impl<I: TS> TS for Range<I> { | |
where | ||
Self: 'static, | ||
{ | ||
().push::<I>() | ||
I::dependency_types() | ||
} | ||
|
||
fn transparent() -> bool { | ||
true | ||
fn generics() -> impl TypeList | ||
where | ||
Self: 'static, | ||
{ | ||
use std::marker::PhantomData; | ||
((PhantomData::<I>,), I::generics()) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ahhh, I got confused by you constructing the TypeList manually here! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really, I just kinda got confused calling methods on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That tripped me up quite a bit in the macros, because the repetition syntax uses parentheses plus the unit type plus the calling of methods There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, yeah, I understand. In this particular case, For the macros, I try to use In the end, this is not a big deal, if you've got strong opinions here. Personally, I prefer using the methods on the type. Edit: I see that you already changed it, thanks! 😆 Being able to call methods on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of that makes a lot of sense! I'll open another PR to apply this change to the impls I changed in #241, all of which manually build a TypeList |
||
|
||
|
@@ -723,11 +698,15 @@ impl<I: TS> TS for RangeInclusive<I> { | |
where | ||
Self: 'static, | ||
{ | ||
().push::<I>() | ||
I::dependency_types() | ||
} | ||
|
||
fn transparent() -> bool { | ||
true | ||
fn generics() -> impl TypeList | ||
where | ||
Self: 'static, | ||
{ | ||
use std::marker::PhantomData; | ||
((PhantomData::<I>,), I::generics()) | ||
} | ||
} | ||
|
||
|
@@ -817,7 +796,4 @@ impl TS for Dummy { | |
fn name() -> String { | ||
"Dummy".to_owned() | ||
} | ||
fn transparent() -> bool { | ||
false | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love that this just works. Awesome!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, since
T::transparent
is alwaysfalse
we just get rid of that check