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

Implement BitOr for common enum types #954

Closed
QueenOfSquiggles opened this issue Nov 29, 2024 · 3 comments
Closed

Implement BitOr for common enum types #954

QueenOfSquiggles opened this issue Nov 29, 2024 · 3 comments
Labels
c: engine Godot classes (nodes, resources, ...) quality-of-life No new functionality, but improves ergonomics/internals

Comments

@QueenOfSquiggles
Copy link

Hey hey. Enum flags could be more intuitive to use if implementing the BitOr trait, which enables support for cases such as:

.connect_ex( /* */ )
  .flags(ConnectFlags::DEFERRED | ConnectFlags::ONE_SHOT)
  .done();

further docs for this trait are available here

A potential implementation could look like:

impl BitOr for ENUM_STRUCT {
  type Output = i32; // or other via type

  fn bitor(self, rhs: Self) -> Self::Output {
    self.to_godot() | rhs.to_godot() 
    // if the via type implements BitOr, this can be used. Else ".ord()" may be needed
  }
}
@Bromeon
Copy link
Member

Bromeon commented Nov 30, 2024

BitOr is already implemented, see https://godot-rust.github.io/docs/gdext/master/godot/classes/object/struct.ConnectFlags.html?search=BitOr.

ConnectFlags may be marked as enum rather than bitfield in the GDExtension API? In that case we'd need to special-case it.

@Bromeon Bromeon added quality-of-life No new functionality, but improves ergonomics/internals c: engine Godot classes (nodes, resources, ...) labels Nov 30, 2024
@Bromeon Bromeon closed this as completed Dec 30, 2024
@Bromeon
Copy link
Member

Bromeon commented Dec 30, 2024

Closed because it's not a missing BitOr issue, but a badly defined ConnectFlags in Godot. I can see if a PR is possible for that, although it might be a breaking change and would have to wait until v0.3.

@Bromeon
Copy link
Member

Bromeon commented Jan 6, 2025

@QueenOfSquiggles I changed the classification of ConnectFlags to bitfield via manual override.
It now supports BitOr: #1002

If you have a chance, could you see if this would work for you?
Do you encounter breaking changes? If yes, just imports or others?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: engine Godot classes (nodes, resources, ...) quality-of-life No new functionality, but improves ergonomics/internals
Projects
None yet
Development

No branches or pull requests

2 participants