Macro swift_rs::swift

source ·
macro_rules! swift {
    ($vis:vis fn $name:ident $(<$($lt:lifetime),+>)? ($($arg:ident: $arg_ty:ty),*) $(-> $ret:ty)?) => { ... };
}
Expand description

Declares a function defined in a swift library. As long as this macro is used, retain counts of arguments and return values will be correct.

Use this macro as if the contents were going directly into an extern "C" block.

use swift_rs::*;

swift!(fn echo(string: &SRString) -> SRString);

let string: SRString = "test".into();
let result = unsafe { echo(&string) };

assert_eq!(result.as_str(), string.as_str())

§Details

Internally this macro creates a wrapping function around an extern "C" block that represents the actual Swift function. This is done in order to restrict the types that can be used as arguments and return types, and to ensure that retain counts of returned values are appropriately balanced.