0.1.52
-
Improve support for order independent declarations. #230 (thanks @NiwakaDev)
-
Support
Vec<PRIMITIVE>
in Swift function argument and return types. #229 (thanks @timwedde)// Rust fn main() { let bytes = ffi::receive_bytes(); println!("bytes: {:?}", bytes); let vec: Vec<u8> = vec![6, 1, 2, 3, 4, 5]; ffi::send_bytes(vec); } #[swift_bridge::bridge] mod ffi { extern "Swift" { fn receive_bytes() -> Vec<u8>; fn send_bytes(vec: Vec<u8>); } }
// Swift func send_bytes(vec: RustVec<UInt8>) { print("Received \(vec.len()) bytes from Rust") for val in vec { print(val) } } func receive_bytes() -> RustVec<UInt8> { let vec = RustVec<UInt8>() for i in 0 ... 4 { vec.push(value: UInt8(i)) } return vec }
-
Support using
already_declared
enums and structs as Swift arguments. #226 (thanks @conectado)// For example, the following is now possible: #[swift_bridge::bridge] mod ffi_i { enum Animal { Alligator, Cat, } } use ffi_i::Foo; #[swift_bridge::bridge] mod ffi { #[swift_bridge(already_declared)] enum Animal {} extern "Swift" { fn hug(a: Animal); } }
-
Support Rust async fn return
Result<(), enum>
. #189 (thanks @NiwakaDev)// Rust #[swift_bridge::bridge] mod ffi { enum SomeEnum { //... } extern "Rust" { async fn some_function() -> Result<(), SomeEnum>; } }
// Swift do { let value = try await some_function() //... } catch let error as SomeEnum { //... } catch { //... }
-
Support Rust async fn return
Result<enum, enum>
. #182 (thanks @NiwakaDev)// Rust #[swift_bridge::bridge] mod ffi { enum NetworkError { NoData, Authentication, } extern "Rust" { type Data; } extern "Rust" { async fn fetch_from_server() -> Result<Data, NetworkError>; } }
// Swift do { let data = try await fetch_from_server() //... } catch let error as NetworkError { //... } catch { //... }
-
Fix and test async Rust fn return
Result<(), OpaqueType>
. #221 (thanks @jfaust) -
Fix and test async Rust fn return
Result<Vec<T>, *>
. #218 (thanks @jfaust) -
Support passing primitive tuples from
Rust -> Swift
. #195 (thanks @NiwakaDev)// Rust #[swift_bridge::bridge] mod ffi { extern "Rust" { fn reflect_tuple_primitives(tuple: (i16, u32)) -> (i16, u32); } } fn reflect_tuple_primitives(tuple: (i16, u32)) -> (i16, u32) { tuple }
// Swift let tuple = reflect_tuple_primitives((-1, 10))
-
Support passing primitive tuples from
Swift -> Rust
. #205 + #211 (thanks @NiwakaDev)// Rust #[swift_bridge::bridge] mod ffi { extern "Swift" { fn swift_reflect_tuple_primitives(arg: (i32, u32)) -> (i32, u32); } }
// Swift let tuple = swift_reflect_tuple_primitives((-123, 123));
-
Support returning
Result<Tuple, *>
from Rust to Swift. #213 (thanks @NiwakaDev)// Rust #[swift_bridge::bridge] mod ffi { extern "Rust" { fn rust_func_return_result_tuple_transparent_enum( succeed: bool, ) -> Result<(i32, ResultTestOpaqueRustType, String), ResultTransparentEnum>; } }
// Swift do { //... let tuple: (Int32, ResultTestOpaqueRustType, RustString) = try rust_func_return_result_tuple_transparent_enum(true) //... } catch { //... }
-
Support
#[derive(Debug)]
on transparent enums. #194 (thanks @naturecodevoid)// Rust #[swift_bridge::bridge] mod ffi { #[derive(Debug)] enum DeriveDebugEnum { Variant, } }
// Swift let debugString = String(reflecting: DeriveDebugEnum.Variant) XCTAssertEqual(debugString, "Variant")
-
Only support the
#[swift_bridge(associated_to)]
attribute on instance methods. #206 (thanks @NiwakaDev) -
Support Option in Swift fns. #203
mod ffi { extern "Swift" { fn my_func(arg: Option<u8>) -> Option<bool>; } }
-
Add
Vec<f32>
andVec<f64>
support. #200 (thanks @rkreutz)#[swift_bridge::bridge] mod ffi { #[swift_bridge(swift_repr = "struct")] struct SomeStruct { field: Vec<f32>, } extern "Rust" { fn do_something(val: SomeStruct) -> Vec<f32>; } } fn do_something(val: SomeStruct) -> Vec<f32> { // ... }
-
Add
#[derive(Copy, Clone)]
support to transparent structs. #198 (thanks @rkreutz)#[swift_bridge::bridge] mod ffi { #[swift_bridge(swift_repr = "struct")] #[derive(Copy, Clone)] struct Foo { field: u8, } }
-
Slightly simplify generated code for returning
Result<(), OpaqueType>
. #184 (thanks @NiwakaDev) -
Support RustString in extern Swift functions. [#225] (thanks @NiwakaDev)
// Swift func reflect_swift_string(arg: RustString) -> RustString { arg }
// Rust #[swift_bridge::bridge] mod ffi { extern "Swift" { fn reflect_swift_string(arg: String) -> String; } } let foo = "foo"; let string = ffi::reflect_swift_string(foo.to_string()); assert_eq!(string.len(), 3); assert_eq!(&string, foo);