-
Support Failable initializers. #276 (thanks @NiwakaDev)
// Rust #[swift_bridge::bridge] mod ffi { extern "Rust" { #[swift_bridge(Equatable)] type FailableInitType; #[swift_bridge(init)] fn new() -> Option<FailableInitType>; } }
// Swift let failableInitType = FailableInitType() if failableInitType == nil { // ... } else { // ... }
-
Support Throwing initializers #287 (thanks @NiwakaDev)
// Rust #[swift_bridge::bridge] mod ffi { enum ResultTransparentEnum { NamedField { data: i32 }, UnnamedFields(u8, String), NoFields, } extern "Rust" { type ThrowingInitializer; #[swift_bridge(init)] fn new(succeed: bool) -> Result<ThrowingInitializer, ResultTransparentEnum>; fn val(&self) -> i32; } }
// Swift do { let throwingInitializer = try ThrowingInitializer(false) } catch let error as ResultTransparentEnum { //... } catch { //... }