add into_std

This commit is contained in:
vms 2021-02-24 08:31:56 +03:00
parent 210fd72b89
commit 292bdc73ea

View File

@ -48,4 +48,16 @@ impl Result {
stderr: Vec::new(),
}
}
/// This function checks ret_code and returns either Ok if it was SUCCESS_CODE or Err otherwise.
///
/// SAFETY:
/// The function relies on both stdout and stderr to contain valid UTF8 string.
unsafe fn into_std(self) -> std::result::Result<String, String> {
if self.ret_code == SUCCESS_CODE {
Ok(String::from_utf8_unchecked(self.stdout))
} else {
Err(String::from_utf8_unchecked(self.stderr))
}
}
}