Skip to content

api: add DeviceId::{into,from}_raw#3941

Merged
kchibisov merged 1 commit intomasterfrom
kchibisov/device-id
Oct 11, 2024
Merged

api: add DeviceId::{into,from}_raw#3941
kchibisov merged 1 commit intomasterfrom
kchibisov/device-id

Conversation

@kchibisov
Copy link
Copy Markdown
Member

@kchibisov kchibisov commented Oct 8, 2024

The same as for WindowId.

This also removes the internal platform ID.

--

I'm not sure what type to pick here, since some use u32, some i32. I think i64 would be the best, but then, negative values for DeviceId are strange?

Also, it's not that clear to what IDs should be limited.

For now I'm just using u64.

Part of #3433.

@daxpedda
Copy link
Copy Markdown
Member

daxpedda commented Oct 8, 2024

Whats the reason for introducing the methods? I would prefer keeping it opaque for the same reasons discussed in #3795.

@kchibisov
Copy link
Copy Markdown
Member Author

@daxpedda we need a way to build those types when backends will be split.

@kchibisov kchibisov force-pushed the kchibisov/device-id branch from 08ebda5 to 293736b Compare October 8, 2024 21:14
@kchibisov
Copy link
Copy Markdown
Member Author

I can make those functions private for now, but they'll be public eventually...

@daxpedda
Copy link
Copy Markdown
Member

daxpedda commented Oct 8, 2024

@daxpedda we need a way to build those types when backends will be split.

No, we can have Winit introduce its own DeviceId type that wraps this one to keep it opaque.
This problem was discussed in the last two meetings.

Generally speaking I'm always leaning towards making compromises internally rather then on the public API, which is to me the most important part of the whole project.

I'm in favor of keeping them private as long as the types are still in the winit crate.

@kchibisov
Copy link
Copy Markdown
Member Author

I mean, if the core types are in winit-core including DeviceId, I'm not sure how you'd create one without e.g. Box or something like that.

Like with a layout like

// winit-core

pub trait DeviceEventHandler: ApplicationHandler {
    fn device_event(&mut self, device_id: Option<DeviceId>, event: Event); 
}

// winit-wayland
{
     // Should be `DeviceId`, but no way to build?
     state.device_event(device_id???, event)
}

It's true that if you re-export everything possible inside the winit and wrap everything, you can probably avoid certain things, but however you can not create traits with types like that, or at least there still should be a type that can be build from e.g. u64.

Unless you just do dyn, but dyn for Id doesn't make any sense.

@kchibisov kchibisov force-pushed the kchibisov/device-id branch from 293736b to ca3162f Compare October 10, 2024 17:40
The same as for `WindowId`.
Copy link
Copy Markdown
Member

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

It's true that if you re-export everything possible inside the winit and wrap everything, you can probably avoid certain things, but however you can not create traits with types like that, or at least there still should be a type that can be build from e.g. u64.

Unless you just do dyn, but dyn for Id doesn't make any sense.

Yeah, makes sense.

Only reviewed the public API and the Web backend, LGTM!

@kchibisov
Copy link
Copy Markdown
Member Author

I've removed public API for now, so should be less concerning.

@kchibisov kchibisov merged commit 4e3165f into master Oct 11, 2024
@kchibisov kchibisov deleted the kchibisov/device-id branch October 11, 2024 08:15
@madsmtm madsmtm added the S - api Design and usability label Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S - api Design and usability

Development

Successfully merging this pull request may close these issues.

4 participants