-
Notifications
You must be signed in to change notification settings - Fork 67
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
Add FromTypeParam #28
Comments
(I can probably work on this myself this weekend if no one beats me.) |
I didn't realize attributes were allowed on type params. Do you have an example of how you'd want to use this? |
Yes. In Servo's code, we have a derivable trait called For example: #[derive(ToCss)]
struct Foo<Bar> {
x: Bar,
} will generate something like impl<Bar> ToCss for Foo<Bar>
where
Bar: ToCss,
{
fn to_css<W>(dest: &mut W) -> fmt::Result where W: fmt::Write {
x.to_css(dest)?;
Ok(())
}
} In some cases, there are fields we don't want to have in the serialization. For those cases, we use However, if a field we want to skip is the only user of a generic parameter, it makes no sense to require that generic parameter to implement #[derive(ToCss)]
struct Foo<Bar> {
#[css(skip)]
x: Bar,
y: u32,
} we would want just impl<Bar> ToCss for Foo<Bar> {
fn to_css<W>(dest: &mut W) -> fmt::Result where W: fmt::Write {
y.to_css(dest)?;
Ok(())
}
} since whether You can always try hard and scan all types to determine whether we need to bind something, but it would be easier if we can simply specify that a generic parameter don't need to be bound, like #[derive(ToCss)]
struct Foo<#[css(no_bound)] Bar> {
#[css(skip)]
x: Bar,
y: u32,
} That being said, it seems attributes on type parameter was just stablized in rust-lang/rust#48851, and will come with Rust 1.26. It is not usable before that. |
This fixes TedDriggs#28.
That shouldn't cause any breaking changes for |
That's right. I realized this when I wrote the test. As far as |
This fixes TedDriggs#28.
* Implement FromTypeParam. This fixes #28.
@upsuper I tried this today on 1.26 stable and it failed saying the feature wasn't stable. I think it got pushed back to 1.27, so I'm going to ship as-is but not try to ship darling's own new usage of the feature. |
TypeParam
may also have attributes, so it would be good to have a trait for that as well.The text was updated successfully, but these errors were encountered: