Skip to content

feat: Add in-place mutation methods#5

Merged
samuelburnham merged 2 commits intomainfrom
mutation
Mar 24, 2026
Merged

feat: Add in-place mutation methods#5
samuelburnham merged 2 commits intomainfrom
mutation

Conversation

@samuelburnham
Copy link
Member

  • Adds a get_mut LeanExternal method to update the opaque type in place if not shared, otherwise copying on write
  • Adds mutating helper functions for arrays and strings
  • Improves docs and tests

Copy link
Member

@arthurpaulino arthurpaulino left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines +1141 to +1153
/// Get a mutable reference to the wrapped data if the external object is
/// exclusively owned (`m_rc == 1`, single-threaded mode).
///
/// Returns `None` if the object is shared or multi-threaded. The `&mut self`
/// requirement ensures unique Rust access, while the `is_exclusive` check
/// ensures unique Lean access.
pub fn get_mut(&mut self) -> Option<&mut T> {
if unsafe { include::lean_is_exclusive(self.0.as_raw()) } {
Some(unsafe { &mut *include::lean_get_external_data(self.0.as_raw()).cast::<T>() })
} else {
None
}
}
Copy link
Member

Choose a reason for hiding this comment

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

👍🏼

@samuelburnham samuelburnham merged commit 2ee6267 into main Mar 24, 2026
10 checks passed
@samuelburnham samuelburnham deleted the mutation branch March 24, 2026 02:15
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.

2 participants