Skip to content

Conversation

davidhozic
Copy link
Owner

@davidhozic davidhozic commented Oct 2, 2025

Closes #61 .

Redesigned the connection between MjModel and MjData (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 as Box<MjModel>.

@davidhozic davidhozic changed the title Feature/sim state with model Generic model reference type for use in lifetime-prohibited contexts Oct 2, 2025
@davidhozic davidhozic marked this pull request as ready for review October 12, 2025 18:07
@davidhozic davidhozic requested a review from Copilot October 12, 2025 18:12
Copy link
Contributor

@Copilot Copilot AI left a 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

@davidhozic davidhozic requested a review from Copilot October 12, 2025 18:14
Copy link
Contributor

@Copilot Copilot AI left a 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.

@davidhozic davidhozic requested a review from Copilot October 12, 2025 18:29
Copy link
Contributor

@Copilot Copilot AI left a 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.

@davidhozic davidhozic merged commit e620bfd into main Oct 12, 2025
1 check passed
@davidhozic davidhozic deleted the feature/sim-state-with-model branch October 12, 2025 18:31
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.

feat: A more flexible simulation state representation

1 participant