You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Swift: Use root object protocol conformance (#2671)
* Use root object protocol conformance
In Swift, extension protocol conformance cannot be made public – it’s tied to the original module (and conformance can’t be re-declared later).
This has implications for cases where types from this library are part of the public API of another library.
For example, in the following setup:
```
+-----------------------------------------------------------+
| Application |
| (calls public API of Wrapper Library) |
| |
| +---------------------------------------------+ |
| | FooLibrary (Library A) | |
| | - Exports select Rust types | |
| | - Associated some free-floating functions | |
| | with types using `public extension` | |
| | +-------------------------------------+ | |
| | | UniFFIWrapper | |
| | +-------------------------------------+ | |
| +---------------------------------------------+ |
| |
+-----------------------------------------------------------+
```
Extension-based Protocol Conformances in `UniFFIWrapper` cannot be made `public` (Swift will say `'public' modifier cannot be used with extensions that declare protocol conformances`). To avoid breaking encapsulation (and thus needing `Application` to import both `FooLibrary` and `UniFFIWrapper` the protocol conformance must be part of the type declaration which _is_ public.
* Add Equatable, Hashable note
* Move `Sendable` conformance back to an extension
Because [`Sendable` is a marker protocol](https://www.swift.org/migration/documentation/swift-6-concurrency-migration-guide/commonproblems/#Retroactive-Sendable-Conformance), the compiler doesn’t need access to any implementation details – that means it can be defined in an extension and still works outside that module.
You can trivially test this by making an `Application`-level object (see the top-level PR description for details) with a signature like::
```swift
struct TestObject: Sendable {
let string: String
let member: MyObject
}
```
If the `Sendable` conformance wasn’t exported correctly, you’d get a compiler warning that “TestObject is not Sendable” but this doesn’t happen.
* Allow objects to use Rust debug_fmt + display_fmt
* Fix bindings
0 commit comments