Skip to content

Implement Associated Types.#6

Merged
althonos merged 4 commits intoalthonos:masterfrom
najamelan:feature/AssocTypes
Jun 5, 2021
Merged

Implement Associated Types.#6
althonos merged 4 commits intoalthonos:masterfrom
najamelan:feature/AssocTypes

Conversation

@najamelan
Copy link
Copy Markdown
Contributor

This implements the associated types of a trait on the blanket impls. Eg:

#[blanket(derive(Rc))]
trait MyTrait { type Return; }

// will generate
impl<MT: MyTrait> MyTrait for Rc<MT>
{
   type Return = <MT as MyTrait>::Return;
}

As before, this is rebased on top of the other PR's, #3, #4, #5. You might want to merge them first.

@najamelan najamelan marked this pull request as draft June 1, 2021 15:16
@najamelan
Copy link
Copy Markdown
Contributor Author

Actually it seems we also need to copy over attributes. I will need to work on this one still.

@najamelan
Copy link
Copy Markdown
Contributor Author

Ok now it copies over attributes. This avoids duplicate types with code like:

#[cfg(target_arch="wasm32")]
type Return;
#[cfg(not(target_arch="wasm32"))]
type Return: Send; 

@najamelan najamelan marked this pull request as ready for review June 1, 2021 16:52
@najamelan najamelan force-pushed the feature/AssocTypes branch from 411eee2 to 007db64 Compare June 4, 2021 17:17
@codecov
Copy link
Copy Markdown

codecov bot commented Jun 4, 2021

Codecov Report

Merging #6 (46cb082) into master (c22888f) will increase coverage by 4.53%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #6      +/-   ##
==========================================
+ Coverage   78.18%   82.72%   +4.53%     
==========================================
  Files           9        9              
  Lines         495      625     +130     
==========================================
+ Hits          387      517     +130     
  Misses        108      108              
Impacted Files Coverage Δ
src/derive/arc.rs 100.00% <100.00%> (ø)
src/derive/box.rs 100.00% <100.00%> (ø)
src/derive/mut.rs 100.00% <100.00%> (ø)
src/derive/rc.rs 100.00% <100.00%> (ø)
src/derive/ref.rs 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c22888f...46cb082. Read the comment docs.

@najamelan najamelan force-pushed the feature/AssocTypes branch from 007db64 to 650ea71 Compare June 4, 2021 17:54
najamelan added 4 commits June 4, 2021 19:59
When adding blanket as a dependency to a blank cargo project, it fails to
compile. This is due to missing features on the syn crate.

This commit adds the needed features. This problem could not be detected
from within the crate itself because features were leaking through from
the dev-dependency of syn which does not have `default-features = false`.

I turned on `resolver = "2"`. This is the new feature resolver for cargo
that will become the default in edition 2021. This is not strictly necessary
but it helps as it no longer leaks features. This means that `cargo check`
will now fail if there are missing features. As `cargo test` obviously turns
on the features from `dev-dependencies`, this will still not detect this
issue.

You might want to check your CI script and add a `cargo check` before
running `cargo test`.
If not you can get duplicate type defs.
@najamelan najamelan force-pushed the feature/AssocTypes branch from 650ea71 to 46cb082 Compare June 4, 2021 18:00
@althonos althonos merged commit 3b493f0 into althonos:master Jun 5, 2021
@althonos
Copy link
Copy Markdown
Owner

althonos commented Jun 5, 2021

That was the last! I'll make a new release with all the changes you implemented. Thanks again!

@najamelan
Copy link
Copy Markdown
Contributor Author

najamelan commented Jun 5, 2021

That was the last! I'll make a new release with all the changes you implemented. Thanks again!

Awesome, glad it worked in the end. Will use in async_executors. We expose like 8 traits that are meant to be used as bounds, so blanket is a relief.

ps: as some feedback, I think it would be possible to eliminate most of the redundancy, as derive is almost identical for all receivers. Either by factoring it out in functions of by generating it with a macro. It would make maintaining and updating the crate a lot less tedious I think.

@althonos
Copy link
Copy Markdown
Owner

althonos commented Jun 5, 2021

@najamelan : Wonderful! Don't hesitate to ping me if something breaks.

I think it would be possible to eliminate most of the redundancy, as derive is almost identical for all receivers.

I agree, but I wanted to know where the code was going before building extra abstractions on top of it 😅 I'll see when I add the two last features I want to implementd (support for Cow with any lifetime, and support for unsized types in Box derive) how much I can refactor there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants