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
Is there a supported way to export a default trait function via swift_bridge? Like this,
structExample;traitExampleTrait{fnexample(&self) -> &'static str{"hello, world"}}implExampleTraitforExample{}#[swift_bridge::bridge]mod example {extern"Rust"{typeExample;fnexample(&self) -> &str;}}
"ExampleTrait" is not in scope in the generated rust module (not surprising), so you get a compile error:
no method named `example` found for reference `&Example` in the current scope
items from traits can only be used if the trait is in scope
I've been looking for a way to trick swift_bridge into producing a "use" item for the trait, but so far no luck. The workarounds I've found all require adding a dummy "impl" block for the struct, which redefines default functions so the bridge can find them. That can be automated with macros.
A more general feature, which would cover the same behavior, would be something like reusable trait bridge definitions. Something like this:
#[swift_bridge::bridge]mod example {extern"Rust"{traitExampleTrait;fnexample(&self) -> &str;}extern"Rust"{structExampleA;implExampleTraitforExampleA;}extern"Rust"{structExampleB;implExampleTraitforExampleB;}}
Do you think either of these features would be a good fit for swift_bridge (default trait functions; reusable trait definitions)? Or is there a better approach?
The text was updated successfully, but these errors were encountered:
in my case, I have two processes communicating over XPC; one written in Swift, one in Rust. the shared request and reply message types are in a Rust crate with a swift_bridge module. For transmission over XPC, I encode/decode them as JSON using serde_json.
There is a trait that looks like this, which all of the data structures implement:
I might have asked about serde<->Codable instead. But approaches for that seemed less obvious, and less generally useful, than trait support.
I know I could define a "MessageMarshaller" concrete type for these functions, instead of trait functions. But default trait functions are pretty common, as are blanket implementations. It would be nice if we could include such functions in the FFI.
Hi there,
Is there a supported way to export a default trait function via swift_bridge? Like this,
"ExampleTrait" is not in scope in the generated rust module (not surprising), so you get a compile error:
I've been looking for a way to trick swift_bridge into producing a "use" item for the trait, but so far no luck. The workarounds I've found all require adding a dummy "impl" block for the struct, which redefines default functions so the bridge can find them. That can be automated with macros.
A more general feature, which would cover the same behavior, would be something like reusable trait bridge definitions. Something like this:
Do you think either of these features would be a good fit for swift_bridge (default trait functions; reusable trait definitions)? Or is there a better approach?
The text was updated successfully, but these errors were encountered: