-
Notifications
You must be signed in to change notification settings - Fork 2
Generic model reference type for use in lifetime-prohibited contexts #70
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
Conversation
… which represents a borrow of the Model
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces generic model reference types for use in lifetime-prohibited contexts by redesigning the connection between MjModel
and MjData
. The change allows users to choose between regular references (requiring lifetime annotations), Rc<MjModel>
, Box<MjModel>
, and other types implementing Deref<Target = MjModel>
.
- Replaces lifetime parameters with generic type parameters bounded by
Deref<Target = MjModel>
- Updates visualization types to accept generic model references
- Adds flexibility for usage in environments with restricted lifetime usage (e.g., Python bindings)
Reviewed Changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/wrappers/mj_data.rs | Converts MjData from lifetime-based to generic type parameter with Deref bound |
src/wrappers/mj_visualization.rs | Updates visualization types to accept generic model references |
src/wrappers/mj_model.rs | Modifies make_data method signature to return MjData<&Self> |
src/viewer.rs | Updates viewer types to use generic model references with Clone bound |
src/renderer.rs | Updates renderer types to use generic model references |
src/util.rs | Modifies macro to support optional generic type parameters |
examples/* | Updates example code to use MjData::new(&model) consistently |
docs/* | Updates documentation to reflect new API and explain generic usage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 25 out of 25 changed files in this pull request and generated no new comments.
Closes #61 .
Redesigned the connection between
MjModel
andMjData
(and several visualization related types) to allow generic types. This gives the user a choice between using a regular reference, which requires lifetime annotations if used as another struct's attribute,Rc<MjModel>
,Box<MjModel>
, etc.For the most part any type that implements
Deref<Target = MjModel>
can be used, with the exception for the renderer and the viewer. Those need some sort of a reference type, e.g.Rc<MjModel>
and &MjModel. This is due to some attributes sharing the value, which forces a reference, thus disallowing owned values such asBox<MjModel>
.