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

Rewrite for better ergonomics and type safety #138

Open
ebkalderon opened this issue Jan 27, 2023 · 1 comment
Open

Rewrite for better ergonomics and type safety #138

ebkalderon opened this issue Jan 27, 2023 · 1 comment
Assignees

Comments

@ebkalderon
Copy link
Owner

ebkalderon commented Jan 27, 2023

This library does some pretty sketchy things internally (abuse of the Deref and DerefMut traits plus some weird, but sound, uses of std::mem::transmute() to simulate inheritance, etc), and its user ergonomics aren't the best either. I've learned quite a lot since I first started this project, and I would like to completely redo this library to make better use of the type system and be more user-friendly.

For one, it is possible to fully reimplement this style of API using 100% safe and idiomatic code (Playground link), while also fixing #93. Other aspects of this library could use a lick of paint; for example, the CaptureOptions interface of the raw RenderDoc API could be abstracted over with a type safe interface, and the frame capture methods could be made more idiomatic too (consider providing a Drop guard for starting and ending a frame capture, for instance).

Finally, the RenderDoc<V> struct could offer a default generic type parameter which defaults to the newest supported API version to make things easier for users who don't really care about selecting a specific API version themselves.

The whole type-safe runtime downgrading API with .into() is honestly an unnecessary gimmick and should be removed. But perhaps offering a fallible API for users to upgrade their RenderDoc<V> instance to a newer version, if they so choose, would be more useful (one would select a minimum supported version first, and if so desired, test at runtime whether RenderDoc handed over a newer version and then switch to that).

@ebkalderon ebkalderon self-assigned this Jan 27, 2023
@ebkalderon
Copy link
Owner Author

ebkalderon commented Jan 29, 2023

There is a work-in-progress branch named improve-api-ergonomics which contains a significant rewrite of this library. It includes, among other things:

  • A proper data model for Versions which uses Minimum<V> and Below<V> trait bounds to conditionally enable and disable methods RenderDoc<V>.
  • A type safe way of upgrading the minimum supported version at runtime.
    • The downgrading mechanism has been removed entirely.
  • Better organization of modules.
  • Strongly typed and versioned capture options.
  • Prettier Debug output for RenderDoc<V> and other versioned types.
  • No more heap allocations when passing InputButtons into set_{focus_toggle,capture}_keys().
  • Clearer documentation, more doctests.
  • Pruned unnecessary items from the public API surface (no more VersionCode enum, no more HasPrevious trait).
    • AsInputButtons remains public so users checking the rustdoc output can see a list of types that implement it.

More ergonomics improvements to come.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant