diff --git a/rust/lib.rs b/rust/lib.rs index 5ae47be..122743c 100644 --- a/rust/lib.rs +++ b/rust/lib.rs @@ -11,7 +11,7 @@ fn say_hello(name: &str) { } #[unsafe(no_mangle)] -extern "C" fn hello(c: *const c_char) -> () { +extern "C" fn hello(c: *const c_char) { say_hello(unsafe { CStr::from_ptr(c) }.to_str().unwrap()) } @@ -23,7 +23,7 @@ struct T { } #[unsafe(no_mangle)] -extern "C" fn hello_struct(t: &T) -> () { +extern "C" fn hello_struct(t: &T) { say_hello(&format!("{:?}", t)) } @@ -35,7 +35,7 @@ enum Shape { } #[unsafe(no_mangle)] -extern "C" fn hello_shape(s: &Shape) -> () { +extern "C" fn hello_shape(s: &Shape) { say_hello(&format!("{:?}", s)) } @@ -80,7 +80,7 @@ enum BTreeC { #[unsafe(no_mangle)] extern "C" fn sum_tree(t: &BTreeC) -> i64 { - (unsafe { std::mem::transmute::<_, &BTree>(t) }).sum() + (unsafe { std::mem::transmute::<&BTreeC, &BTree>(t) }).sum() } #[unsafe(no_mangle)] @@ -89,9 +89,6 @@ extern "C" fn sum_slice(v: *const i64, s: usize) -> i64 { } #[unsafe(no_mangle)] -extern "C" fn print_optional(x: Option<&i8>) -> () { - match x { - Some(x) => println!("{}", x / 2), - None => {} - } +extern "C" fn print_optional(x: Option<&i8>) { + if let Some(x) = x { println!("{}", x / 2) } }