Skip to content

Use delegate-attr to replace delegate #275

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

Closed
wants to merge 3 commits into from

Conversation

upsuper
Copy link

@upsuper upsuper commented Jun 2, 2021

Issue #, if available:

Description of changes: use delegate-attr macro to replace delegate, which should have a nicer syntax.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@zslayton
Copy link
Contributor

zslayton commented Jun 2, 2021

Hi, thanks for the PR! At a glance, it seems like these libraries are a wash for our use case; the bulk of this PR removes a level of indentation. Are there other benefits to using the delegate-attr crate over delegate that we should consider?

@codecov
Copy link

codecov bot commented Jun 2, 2021

Codecov Report

Merging #275 (dd73a7c) into main (d1768e8) will increase coverage by 0.05%.
The diff coverage is 100.00%.

❗ Current head dd73a7c differs from pull request most recent head 3ada6a2. Consider uploading reports for the commit 3ada6a2 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #275      +/-   ##
==========================================
+ Coverage   91.44%   91.49%   +0.05%     
==========================================
  Files          56       55       -1     
  Lines        8241     8093     -148     
==========================================
- Hits         7536     7405     -131     
+ Misses        705      688      -17     
Impacted Files Coverage Δ
src/binary/cursor.rs 91.98% <ø> (ø)
src/reader.rs 94.81% <100.00%> (-0.04%) ⬇️
src/binary/type_code.rs 81.35% <0.00%> (-6.78%) ⬇️
ion-hash/src/lib.rs 96.87% <0.00%> (-3.13%) ⬇️
ion-c-sys/src/string.rs 82.92% <0.00%> (-1.97%) ⬇️
ion-c-sys/src/writer.rs 90.84% <0.00%> (-1.31%) ⬇️
src/binary/timestamp.rs
src/binary/writer.rs 94.66% <0.00%> (+0.16%) ⬆️
ion-hash/src/representation.rs 88.23% <0.00%> (+0.60%) ⬆️
ion-hash/tests/ion_hash_tests.rs 87.93% <0.00%> (+3.08%) ⬆️
... and 1 more

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 d1768e8...3ada6a2. Read the comment docs.

@zslayton
Copy link
Contributor

zslayton commented Jun 2, 2021

Our cargo fmt check is failing for the current commit.

@upsuper
Copy link
Author

upsuper commented Jun 3, 2021

Are there other benefits to using the delegate-attr crate over delegate that we should consider?

I think this way the code looks cleaner, and more friendlier to things like code formatter, as it uses attribute macro rather than function-style macro, for which the formatter can't really know what to do.

Our cargo fmt check is failing for the current commit.

Hmmm, it's very interesting. I think this is a bug of rustfmt, and I'm raising a PR to fix it. In the mean time I think replacing ; with {} would work around this bug. I'll push a new commit to fix it.

@zslayton
Copy link
Contributor

zslayton commented Jun 3, 2021

As this achieves the same thing as our current code but with slightly different syntax, I'm inclined to leave our code as-is. If delegate-attr eventually offers other more objective benefits (for example: better performance), I'd be happy to revisit it.

@zslayton zslayton closed this Jun 3, 2021
@upsuper upsuper deleted the delegate-attr branch June 3, 2021 21:13
@upsuper
Copy link
Author

upsuper commented Jun 3, 2021

I don't think there will be much performance difference as it's just a proc macro... I would note that I think delegate-attr should have a better test coverage, though.

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