CON-382: Feedback on FFI conventions#10
Merged
alejnp merged 3 commits intorticommunity:masterfrom Feb 19, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors FFI-related types and conventions to improve code safety and clarity in the Rust DDS Connector codebase. The changes adopt more idiomatic Rust patterns for FFI, specifically using std::ptr::NonNull<T> for non-null pointer guarantees and improving naming conventions to better reflect the nature of FFI types.
Changes:
- Renamed wrapper types from
Native{}prefix toFfi{}prefix (e.g.,NativeConnector→FfiConnector) to better indicate FFI glue code - Renamed opaque C types from
{}Ptrsuffix toOpaque{}prefix (e.g.,ConnectorPtr→OpaqueConnector) to clarify they are opaque types, not pointers - Changed FFI function parameters from raw pointers to
NonNull<T>for non-null pointer parameters, providing compile-time safety guarantees
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/ffi/rtiddsconnector.rs | Updated opaque type names and FFI function signatures to use NonNull<T> for non-null parameters; changed return type constness for consistency |
| src/ffi/mod.rs | Renamed wrapper types from Native{} to Ffi{}, updated internal storage to use NonNull<T>, and adjusted usage patterns with NonNull::new() |
| src/connector.rs | Updated references from NativeConnector to FfiConnector throughout |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There are some idioms in Rust more suitable for our code, such as using
std::ptr::NonNull.We should prefer these to enforce a safer and cleaner code.
Native{}now holds aNonNull<T>instead of a*const T.NonNull<T>, because the C API expects non-null andNonNull<T>is transparent over*const T.Additionally, we could use the chance to revisit the naming conventions on FFI-related types to better reflect their nature.
Native{}-->Ffi{}: "Native" could refer to anything, but FFI implies "glue".{}Ptr-->Opaque{}: The types were never pointers to begin with.