Hello,
Firstly, am loving Rust so far!!
I have get_id_point() which returns a result. Any way to reduce the boilerplate code when calling it?
fn get_id_point(id: i32, x: i32, y: i32) -> Result<(Id, Point), &'static str> {
let id = Id::from(id)?;
let point = Point::from(x, y)?;
Ok((id, point))
}
// example function which uses get_id_point(), but eventually will be many functions
#[no_mangle]
pub unsafe extern "C" fn place(id: i32, x: i32, y: i32) -> i32 {
let (id, pos) = if let Ok((id, pos)) = get_id_point(id, x, y) {
(id, pos)
} else {
return -1;
};
// ...
0 // everything good, return 0
}
Is there a better approach where with one line I either get back the tuple or I return early with a -1
?
Many thanks for your support!