I am trying to passing in a FFI struct into rust from a Ruby module, mutating the struct and passing back the struct to the ruby module.
What is the proper way to handle the lifetime in this scenario?
I am running into an lifetime error:
src/lib.rs:20:55: 20:70 error: missing lifetime specifier [E0106]
src/lib.rs:20 pub extern fn add_one_to_vals(numbers: TwoNumbers) -> &mut TwoNumbers {
^~~~~~~~~~~~~~~
src/lib.rs:20:55: 20:70 help: run `rustc --explain E0106` to see a detailed explanation
src/lib.rs:20:55: 20:70 help: this function's return type contains a borrowed value, but the signature does not say which one of `numbers`'s 0 elided lifetimes it is borrowed from
Rust code:
pub struct TwoNumbers {
first: i32,
second: i32,
}
impl TwoNumbers {
fn plus_one_to_each(&mut self) -> &mut TwoNumbers {
self.first = self.first + 1;
self.first = self.second + 1;
self
}
}
#[no_mangle]
pub extern fn add_one_to_vals(numbers: TwoNumbers) -> &mut TwoNumbers {
numbers.plus_one_to_each()
}
repr(C)on thatstructif it's used across the boundary at all - Steve Klabnik