Skip to content

fix(derive-encode): Cumulative fixes #267

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ADD-SP
Copy link
Contributor

@ADD-SP ADD-SP commented Apr 16, 2025

Summary

Better to rebase and merge to keep the history.

Better to rebase and merge to keep the history

Keep struct generic parameters (#268)

struct CpuUsageLabelsSet<'a> {
    mode: CpuMode,   // <- an enum
    service: &'a str,
}

Currently, the derive macro EncodeLabelSet doesn't keep the generics in the impl block.

Actually, all generics of LabelSet will be propagated to the struct Family,
which makes concurrency programming much harder.

However, it is also usual to use non-shared Family struct in applications,
introducing lifetime on LabelSet eliminates extra memory copies,
which could improve the performance.

To be honest, this might not shows significant improvement, so I considered it as a fix instead of perf, but this gives the freedom of utilizing lifetime to the end developer.

Emit better compilation error message (#269)

// ========== before ==========
error: proc-macro derive panicked
 --> tests/build/friendly-compilation-error-msg.rs:7:49
  |
7 |     #[derive(Debug, Clone, PartialEq, Eq, Hash, EncodeLabelSet)]
  |                                                 ^^^^^^^^^^^^^^
  |
  = help: message: Can not derive Encode for struct with unnamed fields.
// ========== before ==========

// ========== after==========
error: Can not derive `EncodeLabelSet` for struct with unnamed fields.
 --> tests/build/friendly-compilation-error-msg.rs:8:12
  |
8 |     struct Unnamed(String);
  |            ^^^^^^^
// ========== after==========

Issues

closes #268, closes #269

@ADD-SP ADD-SP force-pushed the add_sp/fix-keep-the-impl-generics branch from 073ec36 to 2eb2dce Compare April 16, 2025 23:36
@ADD-SP ADD-SP marked this pull request as ready for review April 17, 2025 00:04
@ADD-SP ADD-SP changed the title fix(derive-encode): keep struct's generic parameters while deriving EncodeLabelSet fix(derive-encode): Cumulative fixes Apr 17, 2025
@ADD-SP ADD-SP force-pushed the add_sp/fix-keep-the-impl-generics branch from bbf4202 to a63cc15 Compare April 17, 2025 13:32
@ADD-SP ADD-SP force-pushed the add_sp/fix-keep-the-impl-generics branch from a63cc15 to 9f5b1fd Compare April 19, 2025 09:03
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.

Compilation error messages could be better Derive macro doesn't keep the struct's generics
1 participant