rust - Changing the return type of a function returning a Result -


i have crate function sys_info::hostname returns hostname. problem hostname returns result<string, error>, need function must have return type result<(), string>. how can call sys_info::hostname , return hostname in function doesn't return same type? before ask, second function's return type cannot changed due formatting issues.

instead of using try! macro, can't use if result type incompatible, use match statement take apart return value of sys_info::hostname , need parts. example

struct error;  fn thing_returning_result(succeed: bool) -> result<string, error> {     if succeed {         ok("hello".into())     } else {         err(error)     } }  fn thing_returning_other_result(succeed: bool) -> result<(), string> {     match thing_returning_result(succeed) {         ok(s) => err(s),         err(_) => err("whoopsies".into())     } }  fn main() {     println!("{:?}", thing_returning_other_result(false)); } 

Comments