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

more edid functions #3

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

more edid functions #3

wants to merge 4 commits into from

Conversation

cmeissl
Copy link
Collaborator

@cmeissl cmeissl commented Nov 29, 2023

adds more edid functions

based on #2

model_year: value.model_year,
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This is a pretty good example to figure out, how we want to handle data-only structs in the future. Do we always want to make this a separate type? The only thing this converts is the manufacturer array, but that is a valid transmute, so we could also just use a type-alias or wrap the original type + impl some accesors.

I feel like all three have their benefits, this is probably the cleanest api wise, but it also does any conversions upfront and probably requires the most amount of code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I expect that most data only types could be transmuted. But that is pretty error prone if a data type changes or if the type contains an enum which could get extended. I would prefer to not have accessors for everything data only. All types that contain some enum can also not be wrapped in a new type. So to stay consistent, at least for the data only types, I choose the cleanest way. But I agree that this is the most verbose and requires quite some boiler plate code. I could try to come up with a macro or maybe a proc macro to reduce the boiler plate?

Copy link
Member

Choose a reason for hiding this comment

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

Nah, I honestly don't mind that much. I just want a consistent style, which is why I wanted to bring this up.

Level1 = ffi::edid::di_edid_video_input_analog_signal_level_std_DI_EDID_VIDEO_INPUT_ANALOG_SIGNAL_LEVEL_1,
Level2 = ffi::edid::di_edid_video_input_analog_signal_level_std_DI_EDID_VIDEO_INPUT_ANALOG_SIGNAL_LEVEL_2,
Level3 = ffi::edid::di_edid_video_input_analog_signal_level_std_DI_EDID_VIDEO_INPUT_ANALOG_SIGNAL_LEVEL_3,
}
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this is a good approach to enum-like enums. (For bitflags, we probably just want to use the bitflags crate.)

ffi::edid::di_edid_video_input_analog_signal_level_std_DI_EDID_VIDEO_INPUT_ANALOG_SIGNAL_LEVEL_1 => Level1,
ffi::edid::di_edid_video_input_analog_signal_level_std_DI_EDID_VIDEO_INPUT_ANALOG_SIGNAL_LEVEL_2 => Level2,
ffi::edid::di_edid_video_input_analog_signal_level_std_DI_EDID_VIDEO_INPUT_ANALOG_SIGNAL_LEVEL_3 => Level3,
_ => unreachable!()
Copy link
Member

Choose a reason for hiding this comment

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

I haven't checked, if this is covered by the libdisplay-info or edid spec documentation, but how do we want to deal with cases, where later versions might introduce new types? TryFrom and #[non_exhaustive] would be my suggestion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, the consts make this a bit more complicated as we won't get any compile time error if it is extended.
But TryFrom would imply that it can somehow fail, not sure how that would be re-presentable in the data only types. So if we expect the enums to be extended in the future I would suggest to add an Unknown(u32) variant as a generic catcher.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the consts make this a bit more complicated as we won't get any compile time error if it is extended. But TryFrom would imply that it can somehow fail, not sure how that would be re-presentable in the data only types. So if we expect the enums to be extended in the future I would suggest to add an Unknown(u32) variant as a generic catcher.

Only problem with Unknown(u32) is that introducing new variants in the future, will break code that might rely on Unknown(5). So I would rather see the actual value obfuscated in the interest of updating the bindings. But I don't feel particulary strong about this, we could also bumb major versions every time this happens.

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.

None yet

2 participants