refactor: a rusty job

* refactor(jobthread): safe and rusty
* refactor(job): rusty and safe
This commit is contained in:
Friedel Ziegelmayer
2019-08-19 12:07:13 +02:00
committed by GitHub
parent 1a8e08e429
commit a906faeb35
21 changed files with 1491 additions and 1457 deletions

View File

@@ -1284,6 +1284,14 @@ pub fn as_str<'a>(s: *const libc::c_char) -> &'a str {
as_str_safe(s).unwrap_or_else(|err| panic!("{}", err))
}
/// Converts a C string to either a Rust `&str` or `None` if it is a null pointer.
pub fn as_opt_str<'a>(s: *const libc::c_char) -> Option<&'a str> {
if s.is_null() {
return None;
}
Some(as_str(s))
}
fn as_str_safe<'a>(s: *const libc::c_char) -> Result<&'a str, Error> {
assert!(!s.is_null(), "cannot be used on null pointers");