Skip to content
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

Make UserInput generic over the maximum number of chord inputs #241

Closed

Conversation

TimJentzsch
Copy link
Collaborator

Closes #21.

UserInput is now generic over the maximum number of inputs that fit in a chord. The default is still 8.

Furthermore, UserInput::chord doesn't panic anymore if the iterator contains more elements than the maximum size; instead, the rest of the inputs are ignored (breaking change).

Additionally, a UserInput::try_make_chord function does the same thing, but returns a Result and fails when too many inputs were provided. Not sure if this is the best name for this function :P

@alice-i-cecile alice-i-cecile added usability Reduce user friction breaking-change A breaking change that requires a new major version labels Aug 23, 2022
@TimJentzsch
Copy link
Collaborator Author

Hmm, it looks like defaults for const generics are only allowed for structs but not for the method implementations. So you actually need to always specify the constant for UserInput::chord, making it a lot more breaking of a change.

@@ -11,32 +11,41 @@ use crate::{
buttonlike::{MouseMotionDirection, MouseWheelDirection},
};

/// An [`UserInput::Chord`] could not be created because there were too many input elements
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct ChordCreationError;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably return the passed in iterator to make error recovery more feasible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that does make sense, but at the point of error the iterator will already be consumed for the most part, so I'm not sure how useful it will be for recovery

set.insert(button.into());
}

let user_input = match length {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matching behavior is inconsistent with the behavior in the infallible version. It's also surprising, as the user has explicitly tried to make a chord.

Might still be correct, but if so we'll want a different name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it inconsistent? I copied this logic from the infallible version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. Never mind!

///
/// If `inputs` contains more than `CHORD_MAX_SIZE` elements, a [`ChordCreationError`] is returned.
/// If you want to silently ignore the rest of the elements, use the [`UserInput::chord`] function instead.
pub fn try_make_chord(
Copy link
Contributor

@alice-i-cecile alice-i-cecile Aug 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use something super generic here? Like new or try_create or something?

This feels like it should be the default method for configurable keybindings.

@@ -11,6 +11,13 @@
### Usability

- Implemented `Eq` for `Timing` and `InputMap`.
- `UserInput` is now generic over the maximum size of inputs for a `Chord` (the default is still `8`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should probably lower the default to something much smaller, like 4, now that it can be configured, to save space for the 99% of use cases that don't want more.

@alice-i-cecile
Copy link
Contributor

Hmm, it looks like defaults for const generics are only allowed for structs but not for the method implementations. So you actually need to always specify the constant for UserInput::chord, making it a lot more breaking of a change.

This is quite annoying and I think blocks this PR. Is there an issue for this in the rust-lang repo?

@alice-i-cecile alice-i-cecile added the blocked Nothing to do yet label Aug 23, 2022
@TimJentzsch
Copy link
Collaborator Author

This is quite annoying and I think blocks this PR. Is there an issue for this in the rust-lang repo?

Looks like it's this issue: rust-lang/rust#98931.

Turns out you can do something like:

let chord: UserInput = UserInput::chord(...);

but not

let chord = UserInput::chord(...);

...which is kind of weird.
Definitely not ideal for ergonomics though, IMO.

@WalterSmuts
Copy link

WalterSmuts commented Aug 28, 2022

Hmm, it looks like defaults for const generics are only allowed for structs but not for the method implementations. So you actually need to always specify the constant for UserInput::chord, making it a lot more breaking of a change.

@TimJentzsch If possible could you post something on the rust-lang issue to explain your use-case and requirements for a default type feature. AFAICT your objections to the current situation is that it:

  • Has bad ergonomics
  • Forces major version bump (backwards incompatibility) where a minor version bump could've been possible.

Would be great if we can gather a couple of use-cases to show that this is an important feature to add.

@TimJentzsch
Copy link
Collaborator Author

I think this will be obsolete if we use traits instead of enums to represent the user input, which is probably the better move in the long run.

@alice-i-cecile do we already have an issue for this change? I couldn't find one myself

@alice-i-cecile
Copy link
Contributor

@alice-i-cecile do we already have an issue for this change? I couldn't find one myself

Not yet. Let me make one and close this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Nothing to do yet breaking-change A breaking change that requires a new major version usability Reduce user friction
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants