Skip to content

Replace derive_more event helpers with a local macro - #1113

Open
joshka wants to merge 1 commit into
crossterm-rs:masterfrom
joshka:joshka/replace-derive-more-event-macro
Open

Replace derive_more event helpers with a local macro#1113
joshka wants to merge 1 commit into
crossterm-rs:masterfrom
joshka:joshka/replace-derive-more-event-macro

Conversation

@joshka

@joshka joshka commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

This removes the derive_more dependency and feature used to provide the event enum is_* methods.

The public methods and their behavior remain unchanged. They are now generated by a small private macro_rules! macro, while payload-sensitive predicates remain handwritten.

This follows the direction discussed in PR #949, where the tradeoff between boilerplate and an additional proc-macro dependency was discussed. PR #970 subsequently made the dependency optional, but it was still enabled by default.

Why

The generated methods are all simple variant checks, so requiring downstream users to compile derive_more and its proc-macro dependencies is disproportionate to the behavior being added.

The local macro keeps the declarations concise and consistent:

impl_is_variant! {
    Event {
        FocusGained => is_focus_gained,
        Key(..) => is_key,
        Mouse(..) => is_mouse,
    }
}

The variants previously marked is_variant(ignore)KeyCode::F, Char, Media, and Modifier—are intentionally omitted from the macro. They already have handwritten payload-aware methods: is_function_key, is_char, is_media_key, and is_modifier. This avoids duplicate or conflicting methods while preserving their value-sensitive behavior.

Compile-time comparison

These were clean, isolated builds on the same machine and toolchain:

Benchmark Local macro derive_more Difference
Clean crossterm cargo build 2.41s 3.41s +1.00s
Fresh consumer cargo check 2.12s 3.00s +0.88s

The derive_more build additionally compiled proc-macro dependencies including syn, quote, convert_case, derive_more-impl, and derive_more.

For context, PR #949 measured the original fresh-project comparison at 1.851s versus 3.539s, and a clean M2 crate build at 2.016s versus 2.688s. Exact timings vary by toolchain and machine, but the direction is consistent.

Validation

  • cargo fmt --check
  • cargo test --all-targets --locked
  • cargo test --no-default-features --all-targets --locked
  • cargo test --all-features --all-targets --locked
  • cargo clippy --all-targets --all-features --locked -- -D warnings
  • cargo doc --no-deps --all-features --locked

cc @archseer @the-mikedavis

Generate event enum `is_*` helpers locally so crossterm avoids the
derive_more proc-macro dependency while preserving the existing API.
@joshka
joshka force-pushed the joshka/replace-derive-more-event-macro branch from 140fc89 to b712845 Compare August 20, 2026 22:44
@joshka
joshka marked this pull request as ready for review August 21, 2026 17:15
@joshka
joshka requested a review from TimonPost as a code owner August 21, 2026 17:15
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.

1 participant