chinedufn / swift-bridge

swift-bridge facilitates Rust and Swift interop.
https://chinedufn.github.io/swift-bridge
Apache License 2.0
842 stars 62 forks source link

Implement Error for RustStringRef #282

Closed jnbooth closed 1 month ago

jnbooth commented 3 months ago

With the latest versions of Swift, using Result<_, String> causes two errors:

The solution to both errors is for RustStringRef to declare conformance to the Error protocol.

See: Swift Documentation - Error

chinedufn commented 3 months ago

Just needs an integration test.

Potential approach

Bridge a function that returns -> Result<(), String>. Somewhere in here https://github.com/chinedufn/swift-bridge/blob/de059024732fa2f8135a9fe1232b727d96794af6/crates/swift-integration-tests/src/result.rs#L3-L81

Then add a test case that calls that function somewhere inside here https://github.com/chinedufn/swift-bridge/blob/de059024732fa2f8135a9fe1232b727d96794af6/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/ResultTests.swift#L10

On the test case document that (I'm paraphrasing) around the time of Swift x.y returning -> Result<(), String> started giving errors like Thrown expression type 'RustString' does not conform to 'Error'. And that we solved that by implementing Swift's Error protocol for RustStringRef. And that the test is confirming that the Error protocol is indeed implemented.

Then confirm that if you comment out the extension RustStringRef: Error {} line then tests fail.

tmolitor-stud-tu commented 1 month ago

@jnbooth Do you still work on this?

chinedufn commented 1 month ago

Implemented in https://github.com/chinedufn/swift-bridge/pull/296